From 43a9b47615c359d7b99ec73aee0150ff5d6acd27 Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Wed, 21 Oct 2015 21:22:38 -0500 Subject: [PATCH 1/5] (- fix re) Replacing echo usage with printf (This also inclues some clarifications to the comments in `zgen.zsh` and the resulting `init.zsh`.) + making init.zsh comments more consistent + replacing dangerous echos with safer printfs + adding delimiters around inserted values in messages Squashes: 6bc6eded, e5f67616, af27beaf, d93eaa7e --- zgen.zsh | 105 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/zgen.zsh b/zgen.zsh index 7c4fdad..9451d9f 100644 --- a/zgen.zsh +++ b/zgen.zsh @@ -3,6 +3,11 @@ autoload -U regexp-replace local ZGEN_SOURCE="$(cd "$(dirname "${0}")" && pwd -P)" +-zgputs() { printf %s\\n "$@" ;} +-zgpute() { printf %s\\n "-- zgen: $*" >&2 ;} + +-zginit() { -zgputs "$*" >> "${ZGEN_INIT}" ;} + if [[ -z "${ZGEN_DIR}" ]]; then ZGEN_DIR="${HOME}/.zgen" @@ -68,7 +73,7 @@ fi regexp-replace url '/' '-SLASH-' regexp-replace url ':' '-COLON-' regexp-replace url '\|' '-PIPE-' - echo $url + -zgputs "$url" } -zgen-get-clone-dir() { @@ -76,7 +81,7 @@ fi local branch="${2:-master}" if [[ -e "${repo}/.git" ]]; then - echo "${ZGEN_DIR}/local/$(basename ${repo})-${branch}" + -zgputs "${ZGEN_DIR}/local/$(basename ${repo})-${branch}" else # Repo directory will be location/reponame local reponame="$(basename ${repo})" @@ -84,7 +89,7 @@ fi # work well in a filename. local location="$(-zgen-encode-url $(dirname ${repo}))" repo="${location}/${reponame}" - echo "${ZGEN_DIR}/${repo}-${branch}" + -zgputs "${ZGEN_DIR}/${repo}-${branch}" fi } @@ -92,7 +97,7 @@ fi local repo="${1}" if [[ -e "${repo}/.git" ]]; then - echo "${repo}" + -zgputs "${repo}" else # Sourced from antigen url resolution logic. # https://github.com/zsh-users/antigen/blob/master/antigen.zsh @@ -105,7 +110,7 @@ fi ]]; then repo="https://github.com/${repo%.git}.git" fi - echo "${repo}" + -zgputs "${repo}" fi } @@ -190,7 +195,7 @@ zgen-init() { } zgen-reset() { - echo "zgen: Deleting ${ZGEN_INIT}" + -zgpute 'Deleting `'"${ZGEN_INIT}"'` ...' if [[ -f "${ZGEN_INIT}" ]]; then rm "${ZGEN_INIT}" fi @@ -198,7 +203,7 @@ zgen-reset() { zgen-update() { for repo in "${ZGEN_DIR}"/*/*; do - echo "Updating ${repo}" + -zgpute "Updating '${repo}' ..." (cd "${repo}" \ && git pull \ && git submodule update --recursive) @@ -207,72 +212,72 @@ zgen-update() { } zgen-save() { - echo "zgen: Creating ${ZGEN_INIT}" + -zgpute 'Creating `'"${ZGEN_INIT}"'` ...' - echo "#" >! "${ZGEN_INIT}" - echo "# Generated by zgen." >> "${ZGEN_INIT}" - echo "# This file will be overwritten the next time you run zgen save" >> "${ZGEN_INIT}" - echo >> "${ZGEN_INIT}" - echo "ZSH=$(-zgen-get-zsh)" >> "${ZGEN_INIT}" + -zgputs "# {{{" >! "${ZGEN_INIT}" + -zginit "# Generated by zgen." + -zginit "# This file will be overwritten the next time you run zgen save!" + -zginit "" + -zginit "ZSH=$(-zgen-get-zsh)" if [[ ${ZGEN_USE_PREZTO} == 1 ]]; then - echo >> "${ZGEN_INIT}" - echo "# init prezto" >> "${ZGEN_INIT}" + -zginit "" + -zginit "# ### Prezto initialization" for option in "${ZGEN_PREZTO_OPTIONS[@]}"; do - echo "${option}" >> "${ZGEN_INIT}" + -zginit "${option}" done fi - echo >> "${ZGEN_INIT}" - echo "#" >> "${ZGEN_INIT}" + -zginit "" + -zginit "# ### General modules" for file in "${ZGEN_LOADED[@]}"; do - echo "source \"${(q)file}\"" >> "${ZGEN_INIT}" + -zginit 'source "'"${(q)file}"\" done # Set up fpath - echo >> "${ZGEN_INIT}" - echo "#" >> "${ZGEN_INIT}" - echo "# Add our plugins and completions to fpath">> "${ZGEN_INIT}" - echo "#" >> "${ZGEN_INIT}" - echo "fpath=(${(q)ZGEN_COMPLETIONS[@]} \${fpath})" >> "${ZGEN_INIT}" + -zginit "" + -zginit "# ### Plugins & Completions" + -zginit 'fpath=('"${(@q)ZGEN_COMPLETIONS}"' ${fpath})' - # check for file changes + # Check for file changes if [[ ! -z ${ZGEN_RESET_ON_CHANGE} ]]; then - echo >> "${ZGEN_INIT}" - echo "# check for file changes" >> "${ZGEN_INIT}" + -zginit "" + -zginit "# ### Recompilation triggers" for file in ${ZGEN_RESET_ON_CHANGE}; do CHANGESHA=`shasum -a 256 ${file}` - echo "if [[ \"\`shasum -a 256 ${file}\`\" != \"$CHANGESHA\" ]]; then" >> "${ZGEN_INIT}" - echo " echo Changed file ${file}, resetting zgen" >> "${ZGEN_INIT}" - echo " zgen reset" >> "${ZGEN_INIT}" - echo -n "el" >> "${ZGEN_INIT}" + -zginit "if [[ \"\`shasum -a 256 ${file}\`\" != \"$CHANGESHA\" ]]; then" + -zginit ' printf %s\\n Changed file `'"${file}"'`, resetting zgen ...' + -zginit " zgen reset" + printf %s "el" >> "${ZGEN_INIT}" done - echo "se " >> "${ZGEN_INIT}" - echo " ;" >> "${ZGEN_INIT}" - echo "fi" >> "${ZGEN_INIT}" + -zginit "se " + -zginit " ;" + -zginit "fi" fi # load prezto modules if [[ ${ZGEN_USE_PREZTO} == 1 ]]; then - echo >> "${ZGEN_INIT}" - echo "# init prezto" >> "${ZGEN_INIT}" - echo -n "pmodload " >> "${ZGEN_INIT}" + -zginit "" + -zginit "# ### Prezto modules" + printf %s\\n "pmodload" >> "${ZGEN_INIT}" for module in "${ZGEN_PREZTO_LOAD[@]}"; do - echo -n "${module} " >> "${ZGEN_INIT}" + printf %s\\n " ${module}" >> "${ZGEN_INIT}" done - echo >> "${ZGEN_INIT}" fi + -zginit "" + -zginit "# }}}" + zgen-apply --verbose } zgen-apply() { - fpath=(${(q)ZGEN_COMPLETIONS[@]} ${fpath}) + fpath=(${(q-)ZGEN_COMPLETIONS[@]} ${fpath}) [[ "$1" == --verbose ]] && echo "zgen: Creating ${ZGEN_DIR}/zcompdump" compinit -d "${ZGEN_DIR}/zcompdump" } zgen-completions() { - echo "zgen: 'completions' is deprecated, please use 'load' instead" + -zgpute '`zgen completions` is deprecated, please use `zgen load` instead' zgen-load "${@}" } @@ -284,16 +289,16 @@ zgen-completions() { -zgen-get-zsh(){ if [[ ${ZGEN_USE_PREZTO} == 1 ]]; then - echo "$(-zgen-get-clone-dir "$ZGEN_PREZTO_REPO" "$ZGEN_PREZTO_BRANCH")" + -zgputs "$(-zgen-get-clone-dir "$ZGEN_PREZTO_REPO" "$ZGEN_PREZTO_BRANCH")" else - echo "$(-zgen-get-clone-dir "$ZGEN_OH_MY_ZSH_REPO" "$ZGEN_OH_MY_ZSH_BRANCH")" + -zgputs "$(-zgen-get-clone-dir "$ZGEN_OH_MY_ZSH_REPO" "$ZGEN_OH_MY_ZSH_BRANCH")" fi } zgen-load() { if [[ "$#" == 0 ]]; then - echo "zgen: 'load' requires at least one parameter" - echo "usage: zgen load [location] [branch]" + -zgpute '`load` requires at least one parameter:' + -zgpute '`zgen load [location] [branch]`' elif [[ "$#" == 1 && ("${1[1]}" == '/' || "${1[1]}" == '.' ) ]]; then local location="${1}" else @@ -345,7 +350,7 @@ zgen-load() { -zgen-add-to-fpath "${location}" else - echo "zgen: Failed to load ${dir:-$location}" + -zgpute 'Failed to load `'"${dir:-$location}"'`!' fi } @@ -373,7 +378,7 @@ zgen-list() { if [[ -f "${ZGEN_INIT}" ]]; then cat "${ZGEN_INIT}" else - echo "Zgen init.zsh missing, please use zgen save and then restart your shell." + -zgpute '`init.zsh` missing, please use `zgen save` and then restart your shell.' fi } @@ -382,7 +387,7 @@ zgen-selfupdate() { (cd "${ZGEN_SOURCE}" \ && git pull) else - echo "zgen is not running from a git repository, so it is not possible to selfupdate" + -zgpute "Not running from a git repository; cannot automatically update." return 1 fi } @@ -414,7 +419,7 @@ zgen-prezto() { elif [[ $# == 1 ]]; then local module=${file} if [[ -z ${file} ]]; then - echo "Please specify which module to load using 'zgen prezto '" + -zgpute 'Please specify which module to load using `zgen prezto `' return 1 fi -zgen-prezto-load "'$module'" @@ -460,7 +465,7 @@ zgen() { if functions "zgen-${cmd}" > /dev/null ; then "zgen-${cmd}" "${@}" else - echo "zgen: command not found: ${cmd}" + -zgpute 'Command not found: `'"${cmd}"\` fi } From 5176ae6b774d48d0120282a3f618b6ccc9ee2b8f Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Fri, 23 Oct 2015 13:05:02 -0500 Subject: [PATCH 2/5] (new) Don't bother shasum'ing $ZGEN_RESET_ON_CHANGE if mod-times same Squashes: f06aac7c, 12c05019 --- zgen.zsh | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/zgen.zsh b/zgen.zsh index 9451d9f..5a622f5 100644 --- a/zgen.zsh +++ b/zgen.zsh @@ -239,19 +239,27 @@ zgen-save() { -zginit 'fpath=('"${(@q)ZGEN_COMPLETIONS}"' ${fpath})' # Check for file changes - if [[ ! -z ${ZGEN_RESET_ON_CHANGE} ]]; then - -zginit "" - -zginit "# ### Recompilation triggers" - for file in ${ZGEN_RESET_ON_CHANGE}; do - CHANGESHA=`shasum -a 256 ${file}` - -zginit "if [[ \"\`shasum -a 256 ${file}\`\" != \"$CHANGESHA\" ]]; then" - -zginit ' printf %s\\n Changed file `'"${file}"'`, resetting zgen ...' - -zginit " zgen reset" - printf %s "el" >> "${ZGEN_INIT}" - done - -zginit "se " - -zginit " ;" - -zginit "fi" + if [[ ! -z "${ZGEN_RESET_ON_CHANGE}" ]]; then + -zginit "" + -zginit "# ### Recompilation triggers" + + local ages="$(stat -Lc "%Y" 2>/dev/null $ZGEN_RESET_ON_CHANGE || \ + stat -Lf "%m" 2>/dev/null $ZGEN_RESET_ON_CHANGE)" + local shas="$(shasum -a 256 ${ZGEN_RESET_ON_CHANGE})" + + -zginit "read -rd '' ages </dev/null $ZGEN_RESET_ON_CHANGE || \' + -zginit ' stat -Lf "%m" $ZGEN_RESET_ON_CHANGE)" != "$ages" \' + -zginit ' && "$(shasum -a 256 $ZGEN_RESET_ON_CHANGE)" != "$shas" ]]; then' + -zginit ' printf %s\\n '\''-- zgen: Files in $ZGEN_RESET_ON_CHANGE changed; resetting `init.zsh`...'\' + -zginit ' zgen reset' + -zginit 'fi' fi # load prezto modules From e07bf3581d26bd45b72e215f62debaeaaeeea027 Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Wed, 21 Oct 2015 21:19:02 -0500 Subject: [PATCH 3/5] (- fix) Aggregated minor improvements and fixes: - More reliably avoid sourcing the same Zsh file twice - Reset `init.zsh` after `git pull`'ing - Avoid globally including `regex-replace` --- zgen.zsh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/zgen.zsh b/zgen.zsh index 5a622f5..3055372 100644 --- a/zgen.zsh +++ b/zgen.zsh @@ -1,6 +1,4 @@ #!/bin/zsh -autoload -U regexp-replace - local ZGEN_SOURCE="$(cd "$(dirname "${0}")" && pwd -P)" -zgputs() { printf %s\\n "$@" ;} @@ -17,6 +15,10 @@ if [[ -z "${ZGEN_INIT}" ]]; then ZGEN_INIT="${ZGEN_DIR}/init.zsh" fi +if [[-z "${ZGEN_AUTOLOAD_COMPINIT}" ]]; then + ZGEN_AUTOLOAD_COMPINIT=1 +fi + if [[ -z "${ZGEN_LOADED}" ]]; then ZGEN_LOADED=() fi @@ -65,10 +67,10 @@ if [[ -z "${ZGEN_PREZTO_BRANCH}" ]]; then ZGEN_PREZTO_BRANCH=master fi +autoload -U regexp-replace -zgen-encode-url () { # Remove characters from a url that don't work well in a filename. # Inspired by -anti-get-clone-dir() method from antigen. - autoload -U regexp-replace local url="${1}" regexp-replace url '/' '-SLASH-' regexp-replace url ':' '-COLON-' @@ -138,16 +140,14 @@ zgen-clone() { -zgen-source() { local file="${1}" - source "${file}" - - # Add to ZGEN_LOADED array if not present if [[ ! "${ZGEN_LOADED[@]}" =~ "${file}" ]]; then ZGEN_LOADED+=("${file}") - fi + source "${file}" - completion_path="$(dirname ${file})" + completion_path="$(dirname ${file})" - -zgen-add-to-fpath "${completion_path}" + -zgen-add-to-fpath "${completion_path}" + fi } -zgen-prezto-option(){ @@ -393,7 +393,8 @@ zgen-list() { zgen-selfupdate() { if [[ -e "${ZGEN_SOURCE}/.git" ]]; then (cd "${ZGEN_SOURCE}" \ - && git pull) + && git pull) \ + && zgen reset else -zgpute "Not running from a git repository; cannot automatically update." return 1 @@ -481,8 +482,7 @@ ZSH=$(-zgen-get-zsh) zgen-init fpath=($ZGEN_SOURCE $fpath) -ZGEN_AUTOLOAD_COMPINIT=${ZGEN_AUTOLOAD_COMPINIT:-true} -if $ZGEN_AUTOLOAD_COMPINIT; then +if [[ ${ZGEN_AUTOLOAD_COMPINIT} == 1 ]]; then autoload -U compinit compinit -d "${ZGEN_DIR}/zcompdump" fi From b4759df0b636be3f5573a6d5d5ea1d46687e8112 Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Sun, 25 Oct 2015 20:04:47 -0500 Subject: [PATCH 4/5] (fix) Handle compinit-calling much more intelligently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Most importantly, the `zcompdump` is now pre-generated at the same time as `init.zsh`; and then is re-used in subsequent terminals. - `$ZGEN_AUTOLOAD_COMPINIT` is now actually *respected* (pretty sure this was a bug.) - If the user is already calling `compinit` *before* invoking `zgen`, then we'll assume They Know What They're Doing, and not touch it at all. - The `.zcompdump` file is no longer placed in a weird, Zgen-specific location; and is left to be placed in its' default directory. (The user is also allowed to configure this.) See `man zshcompsys`, section “Use of compinit”, for more information: Squashes: 3ecfb729, 2d979f1e --- README.md | 5 +++++ zgen.zsh | 35 +++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5e4c85f..2f42f94 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ Returns 0 if an init script exists. You can set the environment variable ZGEN_RESET_ON_CHANGE. These files will be checked and if a change is detected zgen reset is called. ZGEN_RESET_ON_CHANGE=(${HOME}/.zshrc ${HOME}/.zshrc.local) +### Notes +Be aware that `zgen` tries to handle [`compinit`][compinit] for you to allow for the fastest possible initialization times. However, this functionality will be disabled if you've already called `compinit` yourself before sourcing `zgen.zsh`. (Alternatively, you can disable it yourself by disabling `$ZGEN_AUTOLOAD_COMPINIT`.) + + [compinit]: "Zsh manual 20.2.1: Use of compinit" + ### Example .zshrc ```zsh diff --git a/zgen.zsh b/zgen.zsh index 3055372..8d2349c 100644 --- a/zgen.zsh +++ b/zgen.zsh @@ -15,10 +15,18 @@ if [[ -z "${ZGEN_INIT}" ]]; then ZGEN_INIT="${ZGEN_DIR}/init.zsh" fi -if [[-z "${ZGEN_AUTOLOAD_COMPINIT}" ]]; then +# The user can explicitly disable Zgen attempting to invoke `compinit`, or it +# will be automatically disabled if `compinit` appears to have already been +# invoked. +if [[ -z "${ZGEN_AUTOLOAD_COMPINIT}" && -z "${(t)_comps}" ]]; then ZGEN_AUTOLOAD_COMPINIT=1 fi +if [[ -n "${ZGEN_CUSTOM_COMPDUMP}" ]]; then + ZGEN_COMPINIT_DIR_FLAG="-d ${(q-)ZGEN_CUSTOM_COMPDUMP}" + ZGEN_COMPINIT_FLAGS="${ZGEN_COMPINIT_DIR_FLAG} ${ZGEN_COMPINIT_FLAGS}" +fi + if [[ -z "${ZGEN_LOADED}" ]]; then ZGEN_LOADED=() fi @@ -233,10 +241,17 @@ zgen-save() { -zginit 'source "'"${(q)file}"\" done - # Set up fpath + # Set up fpath, load completions + # NOTE: This *intentionally* doesn't use ${ZGEN_COMPINIT_FLAGS}; the only + # available flags are meaningless in the presence of `-C`. -zginit "" -zginit "# ### Plugins & Completions" -zginit 'fpath=('"${(@q)ZGEN_COMPLETIONS}"' ${fpath})' + if [[ ${ZGEN_AUTOLOAD_COMPINIT} == 1 ]]; then + -zginit "" + -zginit 'autoload -Uz compinit && \' + -zginit ' compinit -C '"${ZGEN_COMPINIT_DIR_FLAG}" + fi # Check for file changes if [[ ! -z "${ZGEN_RESET_ON_CHANGE}" ]]; then @@ -275,13 +290,18 @@ zgen-save() { -zginit "" -zginit "# }}}" - zgen-apply --verbose + zgen-apply } zgen-apply() { fpath=(${(q-)ZGEN_COMPLETIONS[@]} ${fpath}) - [[ "$1" == --verbose ]] && echo "zgen: Creating ${ZGEN_DIR}/zcompdump" - compinit -d "${ZGEN_DIR}/zcompdump" + + if [[ ${ZGEN_AUTOLOAD_COMPINIT} == 1 ]]; then + -zgpute "Initializing completions ..." + + autoload -Uz compinit && \ + compinit $ZGEN_COMPINIT_FLAGS + fi } zgen-completions() { @@ -481,8 +501,3 @@ zgen() { ZSH=$(-zgen-get-zsh) zgen-init fpath=($ZGEN_SOURCE $fpath) - -if [[ ${ZGEN_AUTOLOAD_COMPINIT} == 1 ]]; then - autoload -U compinit - compinit -d "${ZGEN_DIR}/zcompdump" -fi From f4658f73b0ff6629747788047664e87959f849b6 Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Sun, 25 Oct 2015 20:23:18 -0500 Subject: [PATCH 5/5] (- re meta) Normalize whitespace and styling a tad - Trying to normalize whitespace to *some* standard or other, - improving the usage-text on bare invocation, - and adding a modeline, on request. --- zgen.zsh | 73 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/zgen.zsh b/zgen.zsh index 8d2349c..7023629 100644 --- a/zgen.zsh +++ b/zgen.zsh @@ -1,4 +1,5 @@ #!/bin/zsh +# vim: set ft=zsh fenc=utf-8 noai ts=8 et sts=4 sw=0 tw=80 nowrap : local ZGEN_SOURCE="$(cd "$(dirname "${0}")" && pwd -P)" -zgputs() { printf %s\\n "$@" ;} @@ -294,14 +295,14 @@ zgen-save() { } zgen-apply() { - fpath=(${(q-)ZGEN_COMPLETIONS[@]} ${fpath}) + fpath=(${(q-)ZGEN_COMPLETIONS[@]} ${fpath}) - if [[ ${ZGEN_AUTOLOAD_COMPINIT} == 1 ]]; then - -zgpute "Initializing completions ..." + if [[ ${ZGEN_AUTOLOAD_COMPINIT} == 1 ]]; then + -zgpute "Initializing completions ..." - autoload -Uz compinit && \ - compinit $ZGEN_COMPINIT_FLAGS - fi + autoload -Uz compinit && \ + compinit $ZGEN_COMPINIT_FLAGS + fi } zgen-completions() { @@ -311,8 +312,8 @@ zgen-completions() { } -zgen-path-contains() { - setopt localoptions nonomatch nocshnullglob nonullglob; - [ -e "$1"/*"$2"(.,@[1]) ] + setopt localoptions nonomatch nocshnullglob nonullglob; + [ -e "$1"/*"$2"(.,@[1]) ] } -zgen-get-zsh(){ @@ -328,19 +329,19 @@ zgen-load() { -zgpute '`load` requires at least one parameter:' -zgpute '`zgen load [location] [branch]`' elif [[ "$#" == 1 && ("${1[1]}" == '/' || "${1[1]}" == '.' ) ]]; then - local location="${1}" + local location="${1}" else - local repo="${1}" - local file="${2}" - local branch="${3:-master}" - local dir="$(-zgen-get-clone-dir ${repo} ${branch})" - local location="${dir}/${file}" - location=${location%/} - - # clone repo if not present - if [[ ! -d "${dir}" ]]; then - zgen-clone "${repo}" "${branch}" - fi + local repo="${1}" + local file="${2}" + local branch="${3:-master}" + local dir="$(-zgen-get-clone-dir ${repo} ${branch})" + local location="${dir}/${file}" + location=${location%/} + + # clone repo if not present + if [[ ! -d "${dir}" ]]; then + zgen-clone "${repo}" "${branch}" + fi fi # source the file @@ -407,6 +408,7 @@ zgen-list() { cat "${ZGEN_INIT}" else -zgpute '`init.zsh` missing, please use `zgen save` and then restart your shell.' + return 1 fi } @@ -462,30 +464,32 @@ zgen-prezto() { } zgen-pmodule() { - local repo="${1}" - local branch="${2:-master}" + local repo="${1}" + local branch="${2:-master}" - local dir="$(-zgen-get-clone-dir ${repo} ${branch})" + local dir="$(-zgen-get-clone-dir ${repo} ${branch})" - # clone repo if not present - if [[ ! -d "${dir}" ]]; then - zgen-clone "${repo}" "${branch}" - fi + # clone repo if not present + if [[ ! -d "${dir}" ]]; then + zgen-clone "${repo}" "${branch}" + fi - local module=$(basename ${repo}) + local module=$(basename ${repo}) - local preztodir="${ZDOTDIR:-$HOME}/.zprezto/modules/${module}" - if [[ ! -h ${preztodir} ]]; then - ln -s $dir ${preztodir} - fi + local preztodir="${ZDOTDIR:-$HOME}/.zprezto/modules/${module}" + if [[ ! -h ${preztodir} ]]; then + ln -s $dir ${preztodir} + fi - -zgen-prezto-load "'${module}'" + -zgen-prezto-load "'${module}'" } zgen() { local cmd="${1}" if [[ -z "${cmd}" ]]; then - echo "usage: zgen [clone|completions|list|load|oh-my-zsh|pmodule|prezto|reset|save|selfupdate|update]" + -zgputs 'usage: `zgen [command | instruction] [options]`' + -zgputs " commands: list, saved, reset, clone, update, selfupdate" + -zgputs " instructions: load, oh-my-zsh, pmodule, prezto, save, apply" return 1 fi @@ -495,6 +499,7 @@ zgen() { "zgen-${cmd}" "${@}" else -zgpute 'Command not found: `'"${cmd}"\` + return 1 fi }