Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions src/commands/bundle.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function _zulu_bundle_usage() {
# Dump installed packages to file
###
function _zulu_bundle_dump() {
local installed=$(zulu list --installed --short)
local installed=$(zulu list --installed --simple --branch --tag)

# Check if the packagefile exists
if [[ -f $packagefile ]]; then
Expand All @@ -42,7 +42,7 @@ function _zulu_bundle_dump() {
# Uninstall packages not in packagefile
###
function _zulu_bundle_cleanup() {
local -a installed; installed=($(zulu list --installed --short))
local -a installed; installed=($(zulu list --installed --simple --branch --tag))

# Loop through each of the installed packages
for package in "${installed[@]}"; do
Expand Down Expand Up @@ -107,15 +107,47 @@ function _zulu_bundle() {
return $?
fi

local oldIFS=$IFS
IFS=$'\n'

# Load the list of packages
packages=($(cat $packagefile))

IFS=$oldIFS
unset oldIFS

# Loop through the packages
for package in "${packages[@]}"; do
# Check if the package is installed already
if [[ ! -d "$base/packages/$package" ]]; then
# Install the package
zulu install $package
local package_name='' flag='' argument='' install_flags=''

# Separate the package name from any meta information
local -a parts meta
parts=(${(ps/, /)package})
package_name="${parts[1]}"
meta=(${(ps/: /)parts[2]})

# Skip the package if it is already installed
if _zulu_info_is_installed $package_name; then
continue
fi

# Separate the meta information into flags and arguments
if [[ ${#meta} -gt 0 ]]; then
flag="${meta[1]}"
argument="${meta[2]}"

# Create the correct install flags
case ${flag} in
branch )
install_flags="--branch $argument"
;;
tag )
install_flags="--tag $argument"
;;
esac
fi

# Install the package
zulu install ${(ps/ /)install_flags} $package_name
done
}
9 changes: 3 additions & 6 deletions src/commands/install.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ function _zulu_install_package() {
return 1
fi

packagefile="$config/packages"
in_packagefile=$(cat $packagefile | grep -e '^'${package}'$')
if [[ "$in_packagefile" = "" ]]; then
echo "$package" >> $packagefile
fi

return
}

Expand Down Expand Up @@ -176,4 +170,7 @@ function _zulu_install() {
echo "$out"
fi
done

# Write the new packagefile contents
zulu bundle --dump --force
}
163 changes: 84 additions & 79 deletions src/commands/list.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -13,111 +13,122 @@ function _zulu_list_usage() {
echo " -n, --not-installed List non-installed packages"
echo " -s, --simple Hide the 'package installed' indicator"
echo " -t, --type <type> Limit results to packages of <type>"
echo " --branch Print the current branch (if one is checked out)"
echo " --tag Print the current tag (if one is checked out)"
}

function _zulu_list_all() {
function _zulu_list_packages() {
local base index files json packages package type name description pad palength

base=${ZULU_DIR:-"${ZDOTDIR:-$HOME}/.zulu"}
config=${ZULU_CONFIG_DIR:-"${ZDOTDIR:-$HOME}/.config/zulu"}
index="$base/index/packages"

for package in $(/bin/ls $index | grep -v '.md'); do
for package in $(/bin/ls $index); do
json="$(cat $index/$package)"

type=$(jsonval $json 'type')
if [[ -n $package_type && $type != $package_type ]]; then
# If --installed is passed but the package is not installed,
# then skip past it
if [[ -n $installed ]] && ! _zulu_info_is_installed $package; then
continue
fi

if [[ -n $simple ]]; then
name="$package"
lim=30
else
if [[ -d "$base/packages/$package" ]]; then
name="$(_zulu_color green '✔') $package"
lim=36
else
name=" $package"
lim=30
fi
fi

if [[ -n $describe ]]; then
description=$(jsonval $json 'description')
printf '%s' "$name"
printf '%*.*s' 0 $(($lim - ${#name} )) "$(printf '%0.1s' " "{1..60})"
printf '%s\n' "$description"
else
echo $name
# If --not-installed is passed but the package is installed,
# then skip past it
if [[ -n $not_installed ]] && _zulu_info_is_installed $package; then
continue
fi
done

return
}

function _zulu_list_installed() {
local base index files json packages package type description pad palength

base=${ZULU_DIR:-"${ZDOTDIR:-$HOME}/.zulu"}
config=${ZULU_CONFIG_DIR:-"${ZDOTDIR:-$HOME}/.config/zulu"}
index="$base/index/packages"

for package in $(/bin/ls "$base/packages"); do
json="$(cat $index/$package)"

# If --type is passed but the package is not or the
# requested type, then skip past it
type=$(jsonval $json 'type')
if [[ -n $package_type && $type != $package_type ]]; then
continue
fi

if [[ -n $describe ]]; then
description=$(jsonval $json 'description')
# Prevent ZVM from changing the ZSH version
local old_ZVM_AUTO_USE=$ZVM_AUTO_USE
unset ZVM_AUTO_USE

printf '%s' "$package"
printf '%*.*s' 0 $((30 - ${#package} )) "$(printf '%0.1s' " "{1..60})"
printf '%s\n' "$description"
else
echo $package
fi
done
local suffix=''

return
}
# If --branch is specified, get the current checked-out branch
# for the package and print it alongside the name
if [[ -n $branch ]] && _zulu_info_is_installed $package; then
local oldPWD=$PWD
cd "$base/packages/$package"

function _zulu_list_not_installed() {
local base index files json packages package type description pad palength
local current=$(git status --short --branch -uno --ignore-submodules=all | head -1 | awk '{print $2}' 2>/dev/null)
current=${current%...*}

base=${ZULU_DIR:-"${ZDOTDIR:-$HOME}/.zulu"}
config=${ZULU_CONFIG_DIR:-"${ZDOTDIR:-$HOME}/.config/zulu"}
index="$base/index/packages"
if [[ $current != 'HEAD' && $current != 'master' ]]; then
suffix+=", branch: $current"
fi

cd $oldPWD
unset oldPWD
fi

for package in $(/bin/ls $index | grep -v '.md'); do
if [[ ! -d "$base/packages/$package" ]]; then
json="$(cat $index/$package)"
# If --tag is specified, get the current checked-out tag
# for the package and print it alongside the name
if [[ -n $tag ]] && _zulu_info_is_installed $package; then
local oldPWD=$PWD
cd "$base/packages/$package"

type=$(jsonval $json 'type')
if [[ -n $package_type && $type != $package_type ]]; then
continue
local commit=$(git status HEAD -uno --ignore-submodules=all | head -1 | awk '{print $4}' 2>/dev/null)

if [[ -n $commit ]]; then
suffix+=", tag: $commit"
fi

if [[ -n $describe ]]; then
description=$(jsonval $json 'description')
cd $oldPWD
unset oldPWD
fi

# Restore the previous ZVM_AUTO_USE setting
export ZVM_AUTO_USE=$old_ZVM_AUTO_USE
unset old_ZVM_AUTO_USE

printf '%s' "$package"
printf '%*.*s' 0 $((30 - ${#package} )) "$(printf '%0.1s' " "{1..60})"
printf '%s\n' "$description"
# Print out the name of the package, and the installed flag
# unless --simple is passed
if [[ -n $simple ]]; then
name="$package$suffix"
lim=30
else
if _zulu_info_is_installed $package; then
name="$(_zulu_color green '✔') $package$suffix"
lim=42
else
echo $package
name=" $package$suffix"
lim=30
fi
fi

# If --describe is specified, print the description
if [[ -n $describe ]]; then
description=$(jsonval $json 'description')
printf '%s' "$name"
printf '%*.*s' 0 $(($lim - ${#name} )) "$(printf '%0.1s' " "{1..60})"
printf '%s\n' "$description"
else
echo $name
fi
done

return
}

function _zulu_list() {
local help all installed not_installed describe simple package_type
local help all installed not_installed describe simple package_type branch tag

# If no arguments are passed, just print a simple list
# of all installed packages
if [[ $# -eq 0 ]]; then
installed=true
simple=true
_zulu_list_packages
return
fi

# Parse options
zparseopts -D \
Expand All @@ -127,27 +138,21 @@ function _zulu_list() {
a=all -all=all \
d=describe -describe=describe \
s=simple -simple=simple \
t:=package_type -type:=package_type
t:=package_type -type:=package_type \
-branch=branch \
-tag=tag

# Output help and return if requested
if [[ -n $help ]]; then
_zulu_list_usage
return
fi

# Check if the --type option is passed and shift the argument
if [[ -n $package_type ]]; then
shift package_type
fi

if [[ -n $all ]]; then
_zulu_list_all
return
fi

if [[ -n $not_installed ]]; then
_zulu_list_not_installed
return
fi

_zulu_list_installed
# List the packages
_zulu_list_packages
}
17 changes: 12 additions & 5 deletions src/commands/uninstall.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ function _zulu_uninstall_usage() {
# Install a package
###
function _zulu_uninstall_package() {
local package json repo dir file link
local package root

package="$1"

# Double check that the package name has been passed
if [[ -z $package ]]; then
echo $(_zulu_color red "Please specify a package name")
echo
_zulu_uninstall_usage
return 1
fi

# Check if the package is already uninstalled
root="$base/packages/$package"

Expand All @@ -24,10 +32,7 @@ function _zulu_uninstall_package() {
# get populated for some reason
rm -rf "$root"

packagefile="$config/packages"
echo "$(cat $packagefile | grep -v -e "^${package}$")" >! $packagefile

return
return $?
}

###
Expand Down Expand Up @@ -88,4 +93,6 @@ function _zulu_uninstall() {
echo "$out"
fi
done

zulu bundle --dump --force
}