Skip to content

Commit

Permalink
Add zgen bin command
Browse files Browse the repository at this point in the history
  • Loading branch information
jandamm committed Sep 21, 2020
1 parent 863fad0 commit 5642756
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions _zgen
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _zgen_commands=(
"completions:deprecated, please use load instead"
"list:print init.zsh"
"load:clone and load plugin"
"bin:clone and add files to PATH"
"oh-my-zsh:load oh-my-zsh base"
"prezto:load prezto base"
"reset:delete the init.zsh script"
Expand Down
71 changes: 70 additions & 1 deletion zgen.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ zgen-reset() {
-zgpute 'Deleting `'"${ZGEN_CUSTOM_COMPDUMP}"'` ...'
rm -r "${ZGEN_CUSTOM_COMPDUMP}"
fi
if [[ -d "$(-zgen-bin-dir)" ]]; then
-zgpute 'Deleting `'"$(-zgen-bin-dir)"'` ...'
rm -dr $(-zgen-bin-dir)
fi
}

zgen-update() {
Expand Down Expand Up @@ -251,6 +255,12 @@ zgen-save() {
-zginit ' compinit -C '"${ZGEN_COMPINIT_DIR_FLAG}"
fi

if [[ -d "$ZGEN_DIR/_/bin" ]]; then
-zginit ""
-zginit "# ### Bins"
-zginit 'path=('"${ZGEN_DIR}"/_/bin' ${path})'
fi

# Check for file changes
if [[ ! -z "${ZGEN_RESET_ON_CHANGE}" ]]; then
-zginit ""
Expand Down Expand Up @@ -317,6 +327,10 @@ zgen-apply() {
autoload -Uz compinit && \
eval "compinit $ZGEN_COMPINIT_FLAGS"
fi

if [[ -d "$ZGEN_DIR/_/bin" ]]; then
path=("$ZGEN_DIR/_/bin" $path)
fi
}

-zgen-path-contains() {
Expand Down Expand Up @@ -443,6 +457,61 @@ zgen-loadall() {
done
}

-zgen-bin-dir() {
echo "$ZGEN_DIR/_/bin"
}
-zgen-bin() {
local file="${1}"
local name="${2}"
if [[ -z $name ]]; then
name=${file##*/}
fi
destination="$(-zgen-bin-dir)/$name"
if [[ ! -e $destination ]]; then
ln -s $file $destination
fi
}

zgen-bin() {
if [[ "$#" == 0 ]]; then
-zgpute '`load` requires at least one parameter:'
-zgpute '`zgen load <repo> [location] [branch] [name]`'
return
fi
local repo="${1}"
local location="${2%/}"
local branch="${3:-master}"
local name="${4}"
local dir="$(-zgen-get-clone-dir ${repo} ${branch})"

# clone repo if not present
if [[ ! -d "${dir}" ]]; then
zgen-clone "${repo}" "${branch}"
fi

if [[ ! -d "$(-zgen-bin-dir)" ]]; then
mkdir -p "$(-zgen-bin-dir)"
fi

set -o nullglob
if [[ -n $location ]]; then
location="${dir/location}"
if [[ -f "${location}" ]]; then
-zgen-bin "${location}" $name
return
fi
elif [[ -d "${dir}/bin" ]]; then
location="${dir}/bin"
else
location="${dir}"
fi
for file in ${location}/*; do
if [[ -x $file ]]; then
-zgen-bin "$file"
fi
done
}

zgen-list() {
if [[ -f "${ZGEN_INIT}" ]]; then
cat "${ZGEN_INIT}"
Expand Down Expand Up @@ -519,7 +588,7 @@ zgen() {
if [[ -z "${cmd}" ]]; then
-zgputs 'usage: `zgen [command | instruction] [options]`'
-zgputs " commands: list, saved, reset, clone, update, selfupdate, compile"
-zgputs " instructions: load, oh-my-zsh, pmodule, prezto, save, apply"
-zgputs " instructions: load, bin, oh-my-zsh, pmodule, prezto, save, apply"
return 1
fi

Expand Down

0 comments on commit 5642756

Please sign in to comment.