diff --git a/_zplugin b/_zinit similarity index 88% rename from _zplugin rename to _zinit index 043aae69..7c626078 100644 --- a/_zplugin +++ b/_zinit @@ -1,4 +1,4 @@ -#compdef zplugin +#compdef zinit setopt localoptions warncreateglobal typesetsilent @@ -7,9 +7,9 @@ local -a expl typeset -a commands commands=( - zstatus:'overall Zplugin status' + zstatus:'overall Zinit status' times:'statistics on plugin loading times' - self-update:'updates Zplugin' + self-update:'updates Zinit' help:'usage information' man:'manual' env-whitelist:'specify names (also patterns) of parameters to be left unchanged during an unload' @@ -52,10 +52,10 @@ commands=( cdreplay:'replay compdefs (to be done after compinit)' cdclear:'clear compdef replay list' srv:'control a service, command can be: stop,start,restart,next,quit; `next'' moves the service to another Zshell' - recall:'fetch saved ice modifiers and construct `zplugin ice ...'' command' + recall:'fetch saved ice modifiers and construct `zinit ice ...'' command' env-whitelist:'allows to specify names (also patterns) of variables left unchanged during an unload. -v - verbose' bindkeys:'lists bindkeys set up by each plugin' - module:'manage binary Zsh module shipped with Zplugin, see `zplugin module help''' + module:'manage binary Zsh module shipped with Zinit, see `zinit module help''' run:"execute code inside plugin's folder" {add-fpath,fpath}:'add plugin folder to $fpath' ) @@ -66,7 +66,7 @@ _arguments -C \ case $state in command) - _describe -t commands "Zplugin command" commands && ret=0 + _describe -t commands "Zinit command" commands && ret=0 ;; argument) @@ -89,9 +89,9 @@ case $state in load|light) typeset -a plugins - plugins=( "${ZPLGM[PLUGINS_DIR]}"/*(N:t) ) + plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) ) plugins=( "${plugins[@]//---//}" ) - plugins=( "${plugins[@]:#_local/zplugin}" ) + plugins=( "${plugins[@]:#_local/zinit}" ) plugins=( "${plugins[@]:#custom}" ) _alternative \ @@ -102,9 +102,9 @@ case $state in run|fpath|add-fpath) typeset -a plugins - plugins=( "${ZPLGM[PLUGINS_DIR]}"/*(N:t) ) + plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) ) plugins=( "${plugins[@]//---//}" ) - plugins=( "${plugins[@]:#_local/zplugin}" ) + plugins=( "${plugins[@]:#_local/zinit}" ) plugins=( "${plugins[@]:#custom}" ) local -a opts @@ -124,22 +124,22 @@ case $state in compile|stress|edit|glance|recall|update|status|cd|changes|delete) # Plugins typeset -a plugins - plugins=( "${ZPLGM[PLUGINS_DIR]}"/*(N:t) ) + plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) ) plugins=( "${plugins[@]//---//}" ) - plugins=( "${plugins[@]:#_local/zplugin}" ) + plugins=( "${plugins[@]:#_local/zinit}" ) plugins=( "${plugins[@]:#custom}" ) # Snippets local -a snippets snippets_alreadyld local sni - snippets=( "${ZPLGM[SNIPPETS_DIR]}"/**/._zplugin(D/:h) ) - snippets=( ${snippets[@]#${ZPLGM[SNIPPETS_DIR]}/} ) + snippets=( "${ZINIT[SNIPPETS_DIR]}"/**/._zinit(D/:h) ) + snippets=( ${snippets[@]#${ZINIT[SNIPPETS_DIR]}/} ) snippets=( ${snippets[@]/(#b)(http|https|ftp|ftps|scp)--/${match[1]}://} ) snippets=( ${snippets[@]/--//} ) for sni ( ${snippets[@]} ) { - if [[ -n ${ZPLG_SNIPPETS[$sni]} ]]; then + if [[ -n ${ZINIT_SNIPPETS[$sni]} ]]; then snippets_alreadyld+=( $sni ) snippets=( ${snippets[@]:#$sni} ) fi @@ -153,7 +153,7 @@ case $state in unload|report) typeset -a plugins absolute normal - plugins=( "${ZPLG_REGISTERED_PLUGINS[@]:#_local/zplugin}" ) + plugins=( "${ZINIT_REGISTERED_PLUGINS[@]:#_local/zinit}" ) normal=( "${plugins[@]:#%*}" ) absolute=( "${(M)plugins[@]:#%*}" ) absolute=( "${absolute[@]/\%\/\//%/}" ) @@ -185,7 +185,7 @@ case $state in cdisable) # Find enabled completions typeset -a completions - completions=( "${ZPLGM[COMPLETIONS_DIR]}"/_*(N:t) ) + completions=( "${ZINIT[COMPLETIONS_DIR]}"/_*(N:t) ) completions=( "${completions[@]#_}" ) _wanted plugins expl "-- Completion --" \ compadd "$@" -a - completions && \ @@ -195,7 +195,7 @@ case $state in cenable) # Find disabled typeset -a completions - completions=( "${ZPLGM[COMPLETIONS_DIR]}"/[^_]*(N:t) ) + completions=( "${ZINIT[COMPLETIONS_DIR]}"/[^_]*(N:t) ) _wanted plugins expl "-- Completion --" \ compadd "$@" -a - completions && \ ret=0 @@ -207,7 +207,7 @@ case $state in # for completions that can be installed typeset -a plugins completions local p c user plugin - for p in "${ZPLGM[PLUGINS_DIR]}"/*; do + for p in "${ZINIT[PLUGINS_DIR]}"/*; do completions=( "$p"/**/_[^_.][^.]#(N) ) for c in "${completions[@]}"; do p="${p:t}" @@ -228,13 +228,13 @@ case $state in # it has completions that are installed typeset -a plugins completions local p c user plugin - for p in "${ZPLGM[PLUGINS_DIR]}"/*; do + for p in "${ZINIT[PLUGINS_DIR]}"/*; do completions=( "$p"/**/_[^_.][^.]#(N) ) for c in "${completions[@]}"; do cfile="${c:t}" bkpfile="${cfile#_}" # Completion installed, either enabled or disabled? - if [[ -e "${ZPLGM[COMPLETIONS_DIR]}"/"$cfile" || -e "${ZPLGM[COMPLETIONS_DIR]}"/"$bkpfile" ]]; then + if [[ -e "${ZINIT[COMPLETIONS_DIR]}"/"$cfile" || -e "${ZINIT[COMPLETIONS_DIR]}"/"$bkpfile" ]]; then p="${p:t}" user="${p%%---*}" plugin="${p#*---}" @@ -257,13 +257,13 @@ case $state in local -a snippets snippets_alreadyld local sni - snippets=( "${ZPLGM[SNIPPETS_DIR]}"/**/._zplugin(D/:h) ) - snippets=( ${snippets[@]#${ZPLGM[SNIPPETS_DIR]}/} ) + snippets=( "${ZINIT[SNIPPETS_DIR]}"/**/._zinit(D/:h) ) + snippets=( ${snippets[@]#${ZINIT[SNIPPETS_DIR]}/} ) snippets=( ${snippets[@]/(#b)(http|https|ftp|ftps|scp)--/${match[1]}://} ) snippets=( ${snippets[@]/--//} ) for sni ( ${snippets[@]} ) { - if [[ -n ${ZPLG_SNIPPETS[$sni]} ]]; then + if [[ -n ${ZINIT_SNIPPETS[$sni]} ]]; then snippets_alreadyld+=( $sni ) snippets=( ${snippets[@]:#$sni} ) fi @@ -301,14 +301,14 @@ case $state in uncompile) typeset -a plugins - plugins=( "${ZPLGM[PLUGINS_DIR]}"/*(N) ) + plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N) ) typeset -a show_plugins p matches for p in "${plugins[@]}"; do matches=( $p/*.zwc(N) ) if [ "$#matches" -ne "0" ]; then p="${p:t}" - [ "$p" = "_local---zplugin" ] && continue + [ "$p" = "_local---zinit" ] && continue [ "$p" = "custom" ] && continue p="${p//---//}" show_plugins+=( "$p" ) diff --git a/doc/Zsh.gitignore b/doc/Zsh.gitignore index 79c2ccc8..d10de1f7 100644 --- a/doc/Zsh.gitignore +++ b/doc/Zsh.gitignore @@ -9,8 +9,8 @@ .zcalc_history # A popular plugin manager's files -._zplugin -.zplugin_lstupd +._zinit +.zinit_lastupd # zdharma/zshelldoc tool's files zsdoc/data diff --git a/doc/install.sh b/doc/install.sh index 6d0c12ad..4d3490ce 100755 --- a/doc/install.sh +++ b/doc/install.sh @@ -4,17 +4,19 @@ # Clone or pull # -if [ -z "$ZPLG_HOME" ]; then - ZPLG_HOME="${ZDOTDIR:-$HOME}/.zplugin" +ZINIT_HOME="${ZINIT_HOME:-$ZPLG_HOME}" +if [ -z "$ZINIT_HOME" ]; then + ZINIT_HOME="${ZDOTDIR:-$HOME}/.zinit" fi -if [ -z "$ZPLG_BIN_DIR_NAME" ]; then - ZPLG_BIN_DIR_NAME="bin" +ZINIT_BIN_DIR_NAME="${ZINIT_BIN_DIR_NAME:-$ZPLG_BIN_DIR_NAME}" +if [ -z "$ZINIT_BIN_DIR_NAME" ]; then + ZINIT_BIN_DIR_NAME="bin" fi -if ! test -d "$ZPLG_HOME"; then - mkdir "$ZPLG_HOME" - chmod g-rwX "$ZPLG_HOME" +if ! test -d "$ZINIT_HOME"; then + mkdir "$ZINIT_HOME" + chmod g-rwX "$ZINIT_HOME" fi if ! command -v git >/dev/null 2>&1; then @@ -24,34 +26,34 @@ fi # Get the download-progress bar tool if command -v curl >/dev/null 2>&1; then - mkdir -p /tmp/zplugin - cd /tmp/zplugin - curl -fsSLO https://raw.githubusercontent.com/zdharma/zplugin/master/git-process-output.zsh && \ - chmod +x /tmp/zplugin/git-process-output.zsh + mkdir -p /tmp/zinit + cd /tmp/zinit + curl -fsSLO https://raw.githubusercontent.com/zdharma/zinit/master/git-process-output.zsh && \ + chmod +x /tmp/zinit/git-process-output.zsh elif command -v wget >/dev/null 2>&1; then - mkdir -p /tmp/zplugin - cd /tmp/zplugin - wget -q https://raw.githubusercontent.com/zdharma/zplugin/master/git-process-output.zsh && \ - chmod +x /tmp/zplugin/git-process-output.zsh + mkdir -p /tmp/zinit + cd /tmp/zinit + wget -q https://raw.githubusercontent.com/zdharma/zinit/master/git-process-output.zsh && \ + chmod +x /tmp/zinit/git-process-output.zsh fi echo -echo "β–“β–’β–‘ Installing zplugin at $ZPLG_HOME/$ZPLG_BIN_DIR_NAME" -if test -d "$ZPLG_HOME/$ZPLG_BIN_DIR_NAME/.git"; then - cd "$ZPLG_HOME/$ZPLG_BIN_DIR_NAME" +echo "β–“β–’β–‘ Installing DHARMA Initiative Plugin Manager at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" +if test -d "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME/.git"; then + cd "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME" git pull origin master else - cd "$ZPLG_HOME" - { git clone --progress https://github.com/zdharma/zplugin.git "$ZPLG_BIN_DIR_NAME" \ - 2>&1 | { /tmp/zplugin/git-process-output.zsh || cat; } } 2>/dev/null - if [ -d "$ZPLG_BIN_DIR_NAME" ]; then + cd "$ZINIT_HOME" + { git clone --progress https://github.com/zdharma/zinit.git "$ZINIT_BIN_DIR_NAME" \ + 2>&1 | { /tmp/zinit/git-process-output.zsh || cat; } } 2>/dev/null + if [ -d "$ZINIT_BIN_DIR_NAME" ]; then echo - echo "β–“β–’β–‘ Zplugin succesfully installed at $ZPLG_HOME/$ZPLG_BIN_DIR_NAME" - VERSION="$(cat "$ZPLG_HOME/$ZPLG_BIN_DIR_NAME/.git/refs/heads/master" | cut -c1-10)" + echo "β–“β–’β–‘ Zinit succesfully installed at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" + VERSION="$(cat "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME/.git/refs/heads/master" | cut -c1-10)" echo "β–“β–’β–‘ Version: $VERSION" else echo - echo "β–“β–’β–‘ Something went wrong, couldn't install Zplugin at $ZPLG_HOME/$ZPLG_BIN_DIR_NAME" + echo "β–“β–’β–‘ Something went wrong, couldn't install Zinit at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" fi fi @@ -59,26 +61,26 @@ fi # Modify .zshrc # THE_ZDOTDIR="${ZDOTDIR:-$HOME}" -if grep zplugin "$THE_ZDOTDIR/.zshrc" >/dev/null 2>&1; then +if grep zinit\\.zsh "$THE_ZDOTDIR/.zshrc" >/dev/null 2>&1; then echo "β–“β–’β–‘ .zshrc already updated, not making changes" exit 0 fi echo "β–“β–’β–‘ Updating $THE_ZDOTDIR/.zshrc (10 lines of code, at the bottom)" -ZPLG_HOME="$(echo $ZPLG_HOME | sed "s|$HOME|\$HOME|")" +ZINIT_HOME="$(echo $ZINIT_HOME | sed "s|$HOME|\$HOME|")" cat <<-EOF >> "$THE_ZDOTDIR/.zshrc" -### Added by Zplugin's installer -if [[ ! -d $ZPLG_HOME/$ZPLG_BIN_DIR_NAME ]]; then - print -P "%F{33}β–“β–’β–‘ %F{220}Installing Zplugin…%f" - command mkdir -p $ZPLG_HOME - command git clone https://github.com/zdharma/zplugin $ZPLG_HOME/$ZPLG_BIN_DIR_NAME && \\ +### Added by Zinit's installer +if [[ ! -f $ZINIT_HOME/$ZINIT_BIN_DIR_NAME/zinit.zsh ]]; then + print -P "%F{33}β–“β–’β–‘ %F{220}Installing DHARMA Initiative Plugin Manager (zdharma/zinit)…%f" + command mkdir -p $ZINIT_HOME + command git clone https://github.com/zdharma/zinit $ZINIT_HOME/$ZINIT_BIN_DIR_NAME && \\ print -P "%F{33}β–“β–’β–‘ %F{34}Installation successful.%F" || \\ print -P "%F{160}β–“β–’β–‘ The clone has failed.%F" fi -source "$ZPLG_HOME/$ZPLG_BIN_DIR_NAME/zplugin.zsh" -autoload -Uz _zplugin -(( \${+_comps} )) && _comps[zplugin]=_zplugin -### End of Zplugin installer's chunk +source "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME/zinit.zsh" +autoload -Uz _zinit +(( \${+_comps} )) && _comps[zinit]=_zinit +### End of Zinit installer's chunk EOF echo "β–“β–’β–‘ Done" diff --git a/zplugin-autoload.zsh b/zinit-autoload.zsh similarity index 67% rename from zplugin-autoload.zsh rename to zinit-autoload.zsh index 7f75eab2..5f81bb83 100644 --- a/zplugin-autoload.zsh +++ b/zinit-autoload.zsh @@ -1,80 +1,80 @@ # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # Copyright (c) 2019 Sebastian Gniazdowski and contributors -builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" +builtin source ${ZINIT[BIN_DIR]}"/zinit-side.zsh" -ZPLGM[EXTENDED_GLOB]="" +ZINIT[EXTENDED_GLOB]="" # # Backend, low level functions # -# FUNCTION: -zplg-unregister-plugin {{{ -# Removes the plugin from ZPLG_REGISTERED_PLUGINS array and from the +# FUNCTION: .zinit-unregister-plugin <<< +# Removes the plugin from ZINIT_REGISTERED_PLUGINS array and from the # zsh_loaded_plugins array (managed according to the plugin standard) --zplg-unregister-plugin() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-unregister-plugin() { + .zinit-any-to-user-plugin "$1" "$2" local uspl2="${reply[-2]}${${reply[-2]:#(%|/)*}:+/}${reply[-1]}" \ teleid="$3" # If not found, the index will be length+1 - ZPLG_REGISTERED_PLUGINS[${ZPLG_REGISTERED_PLUGINS[(i)$uspl2]}]=() + ZINIT_REGISTERED_PLUGINS[${ZINIT_REGISTERED_PLUGINS[(i)$uspl2]}]=() # Support Zsh plugin standard zsh_loaded_plugins[${zsh_loaded_plugins[(i)$teleid]}]=() - ZPLG_REGISTERED_STATES[$uspl2]="0" -} # }}} -# FUNCTION: -zplg-diff-functions-compute {{{ + ZINIT_REGISTERED_STATES[$uspl2]="0" +} # >>> +# FUNCTION: .zinit-diff-functions-compute <<< # Computes FUNCTIONS that holds new functions added by plugin. -# Uses data gathered earlier by -zplg-diff-functions(). +# Uses data gathered earlier by .zinit-diff-functions(). # # $1 - user/plugin --zplg-diff-functions-compute() { +.zinit-diff-functions-compute() { local uspl2="$1" # Cannot run diff if *_BEFORE or *_AFTER variable is not set # Following is paranoid for *_BEFORE and *_AFTER being only spaces builtin setopt localoptions extendedglob nokshglob noksharrays - [[ "${ZPLGM[FUNCTIONS_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZPLGM[FUNCTIONS_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 + [[ "${ZINIT[FUNCTIONS_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZINIT[FUNCTIONS_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 typeset -A func local i # This includes new functions. Quoting is kept (i.e. no i=${(Q)i}) - for i in "${(z)ZPLGM[FUNCTIONS_AFTER__$uspl2]}"; do + for i in "${(z)ZINIT[FUNCTIONS_AFTER__$uspl2]}"; do func[$i]=1 done # Remove duplicated entries, i.e. existing before. Quoting is kept - for i in "${(z)ZPLGM[FUNCTIONS_BEFORE__$uspl2]}"; do + for i in "${(z)ZINIT[FUNCTIONS_BEFORE__$uspl2]}"; do # if would do unset, then: func[opp+a\[]: invalid parameter name func[$i]=0 done # Store the functions, associating them with plugin ($uspl2) - ZPLGM[FUNCTIONS__$uspl2]="" + ZINIT[FUNCTIONS__$uspl2]="" for i in "${(onk)func[@]}"; do - [[ "${func[$i]}" = "1" ]] && ZPLGM[FUNCTIONS__$uspl2]+="$i " + [[ "${func[$i]}" = "1" ]] && ZINIT[FUNCTIONS__$uspl2]+="$i " done return 0 -} # }}} -# FUNCTION: -zplg-diff-options-compute {{{ +} # >>> +# FUNCTION: .zinit-diff-options-compute <<< # Computes OPTIONS that holds options changed by plugin. -# Uses data gathered earlier by -zplg-diff-options(). +# Uses data gathered earlier by .zinit-diff-options(). # # $1 - user/plugin --zplg-diff-options-compute() { +.zinit-diff-options-compute() { local uspl2="$1" # Cannot run diff if *_BEFORE or *_AFTER variable is not set # Following is paranoid for *_BEFORE and *_AFTER being only spaces builtin setopt localoptions extendedglob nokshglob noksharrays - [[ "${ZPLGM[OPTIONS_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZPLGM[OPTIONS_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 + [[ "${ZINIT[OPTIONS_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZINIT[OPTIONS_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 typeset -A opts_before opts_after opts - opts_before=( "${(z)ZPLGM[OPTIONS_BEFORE__$uspl2]}" ) - opts_after=( "${(z)ZPLGM[OPTIONS_AFTER__$uspl2]}" ) + opts_before=( "${(z)ZINIT[OPTIONS_BEFORE__$uspl2]}" ) + opts_after=( "${(z)ZINIT[OPTIONS_AFTER__$uspl2]}" ) opts=( ) # Iterate through first array (keys the same @@ -88,23 +88,23 @@ ZPLGM[EXTENDED_GLOB]="" # Serialize for reporting local IFS=" " - ZPLGM[OPTIONS__$uspl2]="${(kv)opts[@]}" + ZINIT[OPTIONS__$uspl2]="${(kv)opts[@]}" return 0 -} # }}} -# FUNCTION: -zplg-diff-env-compute {{{ -# Computes ZPLG_PATH, ZPLG_FPATH that hold (f)path components -# added by plugin. Uses data gathered earlier by -zplg-diff-env(). +} # >>> +# FUNCTION: .zinit-diff-env-compute <<< +# Computes ZINIT_PATH, ZINIT_FPATH that hold (f)path components +# added by plugin. Uses data gathered earlier by .zinit-diff-env(). # # $1 - user/plugin --zplg-diff-env-compute() { +.zinit-diff-env-compute() { local uspl2="$1" typeset -a tmp # Cannot run diff if *_BEFORE or *_AFTER variable is not set # Following is paranoid for *_BEFORE and *_AFTER being only spaces builtin setopt localoptions extendedglob nokshglob noksharrays - [[ "${ZPLGM[PATH_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZPLGM[PATH_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 - [[ "${ZPLGM[FPATH_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZPLGM[FPATH_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 + [[ "${ZINIT[PATH_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZINIT[PATH_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 + [[ "${ZINIT[FPATH_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZINIT[FPATH_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 typeset -A path_state fpath_state local i @@ -114,19 +114,19 @@ ZPLGM[EXTENDED_GLOB]="" # # This includes new path elements - for i in "${(z)ZPLGM[PATH_AFTER__$uspl2]}"; do + for i in "${(z)ZINIT[PATH_AFTER__$uspl2]}"; do path_state[${(Q)i}]=1 done # Remove duplicated entries, i.e. existing before - for i in "${(z)ZPLGM[PATH_BEFORE__$uspl2]}"; do + for i in "${(z)ZINIT[PATH_BEFORE__$uspl2]}"; do unset "path_state[$i]" done # Store the path elements, associating them with plugin ($uspl2) - ZPLGM[PATH__$uspl2]="" + ZINIT[PATH__$uspl2]="" for i in "${(onk)path_state[@]}"; do - ZPLGM[PATH__$uspl2]+="${(q)i} " + ZINIT[PATH__$uspl2]+="${(q)i} " done # @@ -134,42 +134,42 @@ ZPLGM[EXTENDED_GLOB]="" # # This includes new path elements - for i in "${(z)ZPLGM[FPATH_AFTER__$uspl2]}"; do + for i in "${(z)ZINIT[FPATH_AFTER__$uspl2]}"; do fpath_state[${(Q)i}]=1 done # Remove duplicated entries, i.e. existing before - for i in "${(z)ZPLGM[FPATH_BEFORE__$uspl2]}"; do + for i in "${(z)ZINIT[FPATH_BEFORE__$uspl2]}"; do unset "fpath_state[$i]" done # Store the path elements, associating them with plugin ($uspl2) - ZPLGM[FPATH__$uspl2]="" + ZINIT[FPATH__$uspl2]="" for i in "${(onk)fpath_state[@]}"; do - ZPLGM[FPATH__$uspl2]+="${(q)i} " + ZINIT[FPATH__$uspl2]+="${(q)i} " done return 0 -} # }}} -# FUNCTION: -zplg-diff-parameter-compute {{{ -# Computes ZPLG_PARAMETERS_PRE, ZPLG_PARAMETERS_POST that hold +} # >>> +# FUNCTION: .zinit-diff-parameter-compute <<< +# Computes ZINIT_PARAMETERS_PRE, ZINIT_PARAMETERS_POST that hold # parameters created or changed (their type) by plugin. Uses -# data gathered earlier by -zplg-diff-parameter(). +# data gathered earlier by .zinit-diff-parameter(). # # $1 - user/plugin --zplg-diff-parameter-compute() { +.zinit-diff-parameter-compute() { local uspl2="$1" typeset -a tmp # Cannot run diff if *_BEFORE or *_AFTER variable is not set # Following is paranoid for *_BEFORE and *_AFTER being only spaces builtin setopt localoptions extendedglob nokshglob noksharrays - [[ "${ZPLGM[PARAMETERS_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZPLGM[PARAMETERS_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 + [[ "${ZINIT[PARAMETERS_BEFORE__$uspl2]}" != *[$'! \t']* || "${ZINIT[PARAMETERS_AFTER__$uspl2]}" != *[$'! \t']* ]] && return 1 # Un-concatenated parameters from moment of diff start and of diff end typeset -A params_before params_after - params_before=( "${(z)ZPLGM[PARAMETERS_BEFORE__$uspl2]}" ) - params_after=( "${(z)ZPLGM[PARAMETERS_AFTER__$uspl2]}" ) + params_before=( "${(z)ZINIT[PARAMETERS_BEFORE__$uspl2]}" ) + params_after=( "${(z)ZINIT[PARAMETERS_AFTER__$uspl2]}" ) # The parameters that changed, with save of what # parameter was when diff started or when diff ended @@ -200,123 +200,123 @@ ZPLGM[EXTENDED_GLOB]="" done # Serialize for reporting - ZPLGM[PARAMETERS_PRE__$uspl2]="${(j: :)${(qkv)params_pre[@]}}" - ZPLGM[PARAMETERS_POST__$uspl2]="${(j: :)${(qkv)params_post[@]}}" + ZINIT[PARAMETERS_PRE__$uspl2]="${(j: :)${(qkv)params_pre[@]}}" + ZINIT[PARAMETERS_POST__$uspl2]="${(j: :)${(qkv)params_post[@]}}" return 0 -} # }}} -# FUNCTION: -zplg-any-to-uspl2 {{{ +} # >>> +# FUNCTION: .zinit-any-to-uspl2 <<< # Converts given plugin-spec to format that's used in keys for hash tables. # So basically, creates string "user/plugin" (this format is called: uspl2). # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - (optional) plugin (only when $1 - i.e. user - given) --zplg-any-to-uspl2() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-any-to-uspl2() { + .zinit-any-to-user-plugin "$1" "$2" [[ "${reply[-2]}" = "%" ]] && REPLY="${reply[-2]}${reply[-1]}" || REPLY="${reply[-2]}${${reply[-2]:#(%|/)*}:+/}${reply[-1]//---//}" -} # }}} -# FUNCTION: -zplg-save-set-extendedglob {{{ +} # >>> +# FUNCTION: .zinit-save-set-extendedglob <<< # Enables extendedglob-option first saving if it was already # enabled, for restoration of this state later. --zplg-save-set-extendedglob() { - [[ -o "extendedglob" ]] && ZPLGM[EXTENDED_GLOB]="1" || ZPLGM[EXTENDED_GLOB]="0" +.zinit-save-set-extendedglob() { + [[ -o "extendedglob" ]] && ZINIT[EXTENDED_GLOB]="1" || ZINIT[EXTENDED_GLOB]="0" builtin setopt extendedglob -} # }}} -# FUNCTION: -zplg-restore-extendedglob {{{ +} # >>> +# FUNCTION: .zinit-restore-extendedglob <<< # Restores extendedglob-option from state saved earlier. --zplg-restore-extendedglob() { - [[ "${ZPLGM[EXTENDED_GLOB]}" = "0" ]] && builtin unsetopt extendedglob || builtin setopt extendedglob -} # }}} -# FUNCTION: -zplg-prepare-readlink {{{ +.zinit-restore-extendedglob() { + [[ "${ZINIT[EXTENDED_GLOB]}" = "0" ]] && builtin unsetopt extendedglob || builtin setopt extendedglob +} # >>> +# FUNCTION: .zinit-prepare-readlink <<< # Prepares readlink command, used for establishing completion's owner. # # $REPLY = ":" or "readlink" --zplg-prepare-readlink() { +.zinit-prepare-readlink() { REPLY=":" if type readlink 2>/dev/null 1>&2; then REPLY="readlink" fi -} # }}} -# FUNCTION: -zplg-clear-report-for {{{ +} # >>> +# FUNCTION: .zinit-clear-report-for <<< # Clears all report data for given user/plugin. This is -# done by resetting all related global ZPLG_* hashes. +# done by resetting all related global ZINIT_* hashes. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - (optional) plugin (only when $1 - i.e. user - given) --zplg-clear-report-for() { - -zplg-any-to-uspl2 "$1" "$2" +.zinit-clear-report-for() { + .zinit-any-to-uspl2 "$1" "$2" # Shadowing - ZPLG_REPORTS[$REPLY]="" - ZPLGM[BINDKEYS__$REPLY]="" - ZPLGM[ZSTYLES__$REPLY]="" - ZPLGM[ALIASES__$REPLY]="" - ZPLGM[WIDGETS_SAVED__$REPLY]="" - ZPLGM[WIDGETS_DELETE__$REPLY]="" + ZINIT_REPORTS[$REPLY]="" + ZINIT[BINDKEYS__$REPLY]="" + ZINIT[ZSTYLES__$REPLY]="" + ZINIT[ALIASES__$REPLY]="" + ZINIT[WIDGETS_SAVED__$REPLY]="" + ZINIT[WIDGETS_DELETE__$REPLY]="" # Function diffing - ZPLGM[FUNCTIONS__$REPLY]="" - ZPLGM[FUNCTIONS_BEFORE__$REPLY]="" - ZPLGM[FUNCTIONS_AFTER__$REPLY]="" + ZINIT[FUNCTIONS__$REPLY]="" + ZINIT[FUNCTIONS_BEFORE__$REPLY]="" + ZINIT[FUNCTIONS_AFTER__$REPLY]="" # Option diffing - ZPLGM[OPTIONS__$REPLY]="" - ZPLGM[OPTIONS_BEFORE__$REPLY]="" - ZPLGM[OPTIONS_AFTER__$REPLY]="" + ZINIT[OPTIONS__$REPLY]="" + ZINIT[OPTIONS_BEFORE__$REPLY]="" + ZINIT[OPTIONS_AFTER__$REPLY]="" # Environment diffing - ZPLGM[PATH__$REPLY]="" - ZPLGM[PATH_BEFORE__$REPLY]="" - ZPLGM[PATH_AFTER__$REPLY]="" - ZPLGM[FPATH__$REPLY]="" - ZPLGM[FPATH_BEFORE__$REPLY]="" - ZPLGM[FPATH_AFTER__$REPLY]="" + ZINIT[PATH__$REPLY]="" + ZINIT[PATH_BEFORE__$REPLY]="" + ZINIT[PATH_AFTER__$REPLY]="" + ZINIT[FPATH__$REPLY]="" + ZINIT[FPATH_BEFORE__$REPLY]="" + ZINIT[FPATH_AFTER__$REPLY]="" # Parameter diffing - ZPLGM[PARAMETERS_PRE__$REPLY]="" - ZPLGM[PARAMETERS_POST__$REPLY]="" - ZPLGM[PARAMETERS_BEFORE__$REPLY]="" - ZPLGM[PARAMETERS_AFTER__$REPLY]="" -} # }}} -# FUNCTION: -zplg-exists-message {{{ + ZINIT[PARAMETERS_PRE__$REPLY]="" + ZINIT[PARAMETERS_POST__$REPLY]="" + ZINIT[PARAMETERS_BEFORE__$REPLY]="" + ZINIT[PARAMETERS_AFTER__$REPLY]="" +} # >>> +# FUNCTION: .zinit-exists-message <<< # Checks if plugin is loaded. Testable. Also outputs error # message if plugin is not loaded. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - (optional) plugin (only when $1 - i.e. user - given) --zplg-exists-message() { - -zplg-any-to-uspl2 "$1" "$2" - if [[ -z "${ZPLG_REGISTERED_PLUGINS[(r)$REPLY]}" ]]; then - -zplg-any-colorify-as-uspl2 "$1" "$2" - print "${ZPLGM[col-error]}No such plugin${ZPLGM[col-rst]} $REPLY" +.zinit-exists-message() { + .zinit-any-to-uspl2 "$1" "$2" + if [[ -z "${ZINIT_REGISTERED_PLUGINS[(r)$REPLY]}" ]]; then + .zinit-any-colorify-as-uspl2 "$1" "$2" + print "${ZINIT[col-error]}No such plugin${ZINIT[col-rst]} $REPLY" return 1 fi return 0 -} # }}} -# FUNCTION: -zplg-at-eval {{{ --zplg-at-eval() { +} # >>> +# FUNCTION: .zinit-at-eval <<< +.zinit-at-eval() { local atclone="$2" atpull="$1" integer retval - -zplg-substitute atclone atpull + .zinit-substitute atclone atpull [[ $atpull = "%atclone" ]] && { eval "$atclone"; retval=$?; } || { eval "$atpull"; retval=$?; } return $retval } -# }}} +# >>> # # Format functions # -# FUNCTION: -zplg-format-functions {{{ +# FUNCTION: .zinit-format-functions <<< # Creates a one or two columns text with functions created # by given plugin. # # $1 - user/plugin (i.e. uspl2 format of plugin-spec) --zplg-format-functions() { +.zinit-format-functions() { local uspl2="$1" typeset -a func - func=( "${(z)ZPLGM[FUNCTIONS__$uspl2]}" ) + func=( "${(z)ZINIT[FUNCTIONS__$uspl2]}" ) # Get length of longest left-right string pair, # and length of longest left string @@ -358,26 +358,26 @@ ZPLGM[EXTENDED_GLOB]="" REPLY="$answer" # == 0 is: next element would have newline (postfix addition in "count ++") (( COLUMNS >= longest && count % 2 == 0 )) && REPLY="$REPLY"$'\n' -} # }}} -# FUNCTION: -zplg-format-options {{{ +} # >>> +# FUNCTION: .zinit-format-options <<< # Creates one-column text about options that changed when # plugin "$1" was loaded. # # $1 - user/plugin (i.e. uspl2 format of plugin-spec) --zplg-format-options() { +.zinit-format-options() { local uspl2="$1" REPLY="" # Paranoid, don't want bad key/value pair error integer empty=0 - -zplg-save-set-extendedglob - [[ "${ZPLGM[OPTIONS__$uspl2]}" != *[$'! \t']* ]] && empty=1 - -zplg-restore-extendedglob + .zinit-save-set-extendedglob + [[ "${ZINIT[OPTIONS__$uspl2]}" != *[$'! \t']* ]] && empty=1 + .zinit-restore-extendedglob (( empty )) && return 0 typeset -A opts - opts=( "${(z)ZPLGM[OPTIONS__$uspl2]}" ) + opts=( "${(z)ZINIT[OPTIONS__$uspl2]}" ) # Get length of longest option integer longest=0 @@ -392,23 +392,23 @@ ZPLGM[EXTENDED_GLOB]="" [[ "${opts[$k]}" = "on" ]] && txt="was unset" || txt="was set" REPLY+="${(r:longest+1:: :)k}$txt"$'\n' done -} # }}} -# FUNCTION: -zplg-format-env {{{ +} # >>> +# FUNCTION: .zinit-format-env <<< # Creates one-column text about FPATH or PATH elements # added when given plugin was loaded. # # $1 - user/plugin (i.e. uspl2 format of plugin-spec) # $2 - if 1, then examine PATH, if 2, then examine FPATH --zplg-format-env() { +.zinit-format-env() { local uspl2="$1" which="$2" # Format PATH? if [[ "$which" = "1" ]]; then typeset -a elem - elem=( "${(z@)ZPLGM[PATH__$uspl2]}" ) + elem=( "${(z@)ZINIT[PATH__$uspl2]}" ) elif [[ "$which" = "2" ]]; then typeset -a elem - elem=( "${(z@)ZPLGM[FPATH__$uspl2]}" ) + elem=( "${(z@)ZINIT[FPATH__$uspl2]}" ) fi # Enumerate elements added @@ -420,22 +420,22 @@ ZPLGM[EXTENDED_GLOB]="" done [[ -n "$answer" ]] && REPLY="$answer" -} # }}} -# FUNCTION: -zplg-format-parameter {{{ +} # >>> +# FUNCTION: .zinit-format-parameter <<< # Creates one column text that lists global parameters that # changed when the given plugin was loaded. # # $1 - user/plugin (i.e. uspl2 format of plugin-spec) --zplg-format-parameter() { - local uspl2="$1" infoc="${ZPLGM[col-info]}" k +.zinit-format-parameter() { + local uspl2="$1" infoc="${ZINIT[col-info]}" k builtin setopt localoptions extendedglob nokshglob noksharrays REPLY="" - [[ "${ZPLGM[PARAMETERS_PRE__$uspl2]}" != *[$'! \t']* || "${ZPLGM[PARAMETERS_POST__$uspl2]}" != *[$'! \t']* ]] && return 0 + [[ "${ZINIT[PARAMETERS_PRE__$uspl2]}" != *[$'! \t']* || "${ZINIT[PARAMETERS_POST__$uspl2]}" != *[$'! \t']* ]] && return 0 typeset -A elem_pre elem_post - elem_pre=( "${(z)ZPLGM[PARAMETERS_PRE__$uspl2]}" ) - elem_post=( "${(z)ZPLGM[PARAMETERS_POST__$uspl2]}" ) + elem_pre=( "${(z)ZINIT[PARAMETERS_PRE__$uspl2]}" ) + elem_post=( "${(z)ZINIT[PARAMETERS_POST__$uspl2]}" ) # Find longest key and longest value integer longest=0 vlongest1=0 vlongest2=0 @@ -461,19 +461,19 @@ ZPLGM[EXTENDED_GLOB]="" k="${(r:longest+1:: :)k}" v1="${(l:vlongest1+1:: :)v1}" v2="${(r:vlongest2+1:: :)v2}" - answer+="$k ${infoc}[$v1 -> $v2]${ZPLGM[col-rst]}"$'\n' + answer+="$k ${infoc}[$v1 -> $v2]${ZINIT[col-rst]}"$'\n' done [[ -n "$answer" ]] && REPLY="$answer" return 0 -} # }}} +} # >>> # # Completion functions # -# FUNCTION: -zplg-get-completion-owner {{{ +# FUNCTION: .zinit-get-completion-owner <<< # Returns "user---plugin" string (uspl1 format) of plugin that # owns given completion. # @@ -486,14 +486,14 @@ ZPLGM[EXTENDED_GLOB]="" # # $1 - absolute path to completion file (in COMPLETIONS_DIR) # $2 - readlink command (":" or "readlink") --zplg-get-completion-owner() { +.zinit-get-completion-owner() { setopt localoptions extendedglob nokshglob noksharrays noshwordsplit local cpath="$1" local readlink_cmd="$2" local in_plugin_path tmp # Try to go not too deep into resolving the symlink, - # to have the name as it is in .zplugin/plugins + # to have the name as it is in .zinit/plugins # :A goes deep, descends fully to origin directory # Readlink just reads what symlink points to in_plugin_path="${cpath:A}" @@ -503,7 +503,7 @@ ZPLGM[EXTENDED_GLOB]="" if [[ "$in_plugin_path" != "$cpath" ]]; then # Get the user---plugin part of path - while [[ "$in_plugin_path" != ${ZPLGM[PLUGINS_DIR]}/[^/]## && "$in_plugin_path" != "/" ]]; do + while [[ "$in_plugin_path" != ${ZINIT[PLUGINS_DIR]}/[^/]## && "$in_plugin_path" != "/" ]]; do in_plugin_path="${in_plugin_path:h}" done in_plugin_path="${in_plugin_path:t}" @@ -517,34 +517,34 @@ ZPLGM[EXTENDED_GLOB]="" fi REPLY="$in_plugin_path" -} # }}} -# FUNCTION: -zplg-get-completion-owner-uspl2col {{{ +} # >>> +# FUNCTION: .zinit-get-completion-owner-uspl2col <<< # For shortening of code -Β returns colorized plugin name # that owns given completion. # # $1 - absolute path to completion file (in COMPLETIONS_DIR) # $2 - readlink command (":" or "readlink") --zplg-get-completion-owner-uspl2col() { +.zinit-get-completion-owner-uspl2col() { # "cpath" "readline_cmd" - -zplg-get-completion-owner "$1" "$2" - -zplg-any-colorify-as-uspl2 "$REPLY" -} # }}} -# FUNCTION: -zplg-find-completions-of-plugin {{{ + .zinit-get-completion-owner "$1" "$2" + .zinit-any-colorify-as-uspl2 "$REPLY" +} # >>> +# FUNCTION: .zinit-find-completions-of-plugin <<< # Searches for completions owned by given plugin. # Returns them in `reply' array. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-find-completions-of-plugin() { +.zinit-find-completions-of-plugin() { builtin setopt localoptions nullglob extendedglob nokshglob noksharrays - -zplg-any-to-user-plugin "$1" "$2" + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" uspl [[ "$user" = "%" ]] && uspl="${user}${plugin}" || uspl="${reply[-2]}${reply[-2]:+---}${reply[-1]//\//---}" - reply=( "${ZPLGM[PLUGINS_DIR]}/$uspl"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN) ) -} # }}} -# FUNCTION: -zplg-check-comp-consistency {{{ -# Zplugin creates symlink for each installed completion. + reply=( "${ZINIT[PLUGINS_DIR]}/$uspl"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN) ) +} # >>> +# FUNCTION: .zinit-check-comp-consistency <<< +# Zinit creates symlink for each installed completion. # This function checks whether given completion (i.e. # file like "_mkdir") is indeed a symlink. Backup file # is a completion that is disabled - has the leading "_" @@ -552,47 +552,47 @@ ZPLGM[EXTENDED_GLOB]="" # # $1 - path to completion within plugin's directory # $2 - path to backup file within plugin's directory --zplg-check-comp-consistency() { +.zinit-check-comp-consistency() { local cfile="$1" bkpfile="$2" integer error="$3" # bkpfile must be a symlink if [[ -e "$bkpfile" && ! -L "$bkpfile" ]]; then - print "${ZPLGM[col-error]}Warning: completion's backup file \`${bkpfile:t}' isn't a symlink${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}Warning: completion's backup file \`${bkpfile:t}' isn't a symlink${ZINIT[col-rst]}" error=1 fi # cfile must be a symlink if [[ -e "$cfile" && ! -L "$cfile" ]]; then - print "${ZPLGM[col-error]}Warning: completion file \`${cfile:t}' isn't a symlink${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}Warning: completion file \`${cfile:t}' isn't a symlink${ZINIT[col-rst]}" error=1 fi # Tell user that he can manually modify but should do it right - (( error )) && print "${ZPLGM[col-error]}Manual edit of ${ZPLGM[COMPLETIONS_DIR]} occured?${ZPLGM[col-rst]}" -} # }}} -# FUNCTION: -zplg-check-which-completions-are-installed {{{ + (( error )) && print "${ZINIT[col-error]}Manual edit of ${ZINIT[COMPLETIONS_DIR]} occured?${ZINIT[col-rst]}" +} # >>> +# FUNCTION: .zinit-check-which-completions-are-installed <<< # For each argument that each should be a path to completion # within a plugin's dir, it checks whether that completion # is installed - returns 0 or 1 on corresponding positions # in reply. # # $1, ... - path to completion within plugin's directory --zplg-check-which-completions-are-installed() { +.zinit-check-which-completions-are-installed() { local i cfile bkpfile reply=( ) for i in "$@"; do cfile="${i:t}" bkpfile="${cfile#_}" - if [[ -e "${ZPLGM[COMPLETIONS_DIR]}"/"$cfile" || -e "${ZPLGM[COMPLETIONS_DIR]}"/"$bkpfile" ]]; then + if [[ -e "${ZINIT[COMPLETIONS_DIR]}"/"$cfile" || -e "${ZINIT[COMPLETIONS_DIR]}"/"$bkpfile" ]]; then reply+=( "1" ) else reply+=( "0" ) fi done -} # }}} -# FUNCTION: -zplg-check-which-completions-are-enabled {{{ +} # >>> +# FUNCTION: .zinit-check-which-completions-are-enabled <<< # For each argument that each should be a path to completion # within a plugin's dir, it checks whether that completion # is disabled - returns 0 or 1 on corresponding positions @@ -602,33 +602,33 @@ ZPLGM[EXTENDED_GLOB]="" # - i.e. disabled # # $1, ... - path to completion within plugin's directory --zplg-check-which-completions-are-enabled() { +.zinit-check-which-completions-are-enabled() { local i cfile reply=( ) for i in "$@"; do cfile="${i:t}" - if [[ -e "${ZPLGM[COMPLETIONS_DIR]}"/"$cfile" ]]; then + if [[ -e "${ZINIT[COMPLETIONS_DIR]}"/"$cfile" ]]; then reply+=( "1" ) else reply+=( "0" ) fi done -} # }}} -# FUNCTION: -zplg-uninstall-completions {{{ +} # >>> +# FUNCTION: .zinit-uninstall-completions <<< # Removes all completions of given plugin from Zshell (i.e. from FPATH). -# The FPATH is typically `~/.zplugin/completions/'. +# The FPATH is typically `~/.zinit/completions/'. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-uninstall-completions() { +.zinit-uninstall-completions() { builtin setopt localoptions nullglob extendedglob unset nokshglob noksharrays noshwordsplit typeset -a completions symlinked backup_comps local c cfile bkpfile integer action global_action=0 - -zplg-get-path "$1" "$2" + .zinit-get-path "$1" "$2" [[ -e "$REPLY" ]] && { completions=( "$REPLY"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN) ) } || { @@ -636,8 +636,8 @@ ZPLGM[EXTENDED_GLOB]="" return 1 } - symlinked=( "${ZPLGM[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc ) - backup_comps=( "${ZPLGM[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) + symlinked=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc ) + backup_comps=( "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) # Delete completions if they are really there, either # as completions (_fname) or backups (fname) @@ -648,41 +648,41 @@ ZPLGM[EXTENDED_GLOB]="" # Remove symlink to completion if [[ -n "${symlinked[(r)*/$cfile]}" ]]; then - command rm -f "${ZPLGM[COMPLETIONS_DIR]}/$cfile" + command rm -f "${ZINIT[COMPLETIONS_DIR]}/$cfile" action=1 fi # Remove backup symlink (created by cdisable) if [[ -n "${backup_comps[(r)*/$bkpfile]}" ]]; then - command rm -f "${ZPLGM[COMPLETIONS_DIR]}/$bkpfile" + command rm -f "${ZINIT[COMPLETIONS_DIR]}/$bkpfile" action=1 fi if (( action )); then - print "${ZPLGM[col-info]}Uninstalling completion \`$cfile'${ZPLGM[col-rst]}" + print "${ZINIT[col-info]}Uninstalling completion \`$cfile'${ZINIT[col-rst]}" # Make compinit notice the change - -zplg-forget-completion "$cfile" + .zinit-forget-completion "$cfile" (( global_action ++ )) else - print "${ZPLGM[col-info]}Completion \`$cfile' not installed${ZPLGM[col-rst]}" + print "${ZINIT[col-info]}Completion \`$cfile' not installed${ZINIT[col-rst]}" fi done if (( global_action > 0 )); then - print "${ZPLGM[col-info]}Uninstalled $global_action completions${ZPLGM[col-rst]}" + print "${ZINIT[col-info]}Uninstalled $global_action completions${ZINIT[col-rst]}" fi - (( ${+functions[-zplg-forget-completion]} )) || builtin source ${ZPLGM[BIN_DIR]}"/zplugin-install.zsh" - -zplg-compinit >/dev/null -} # }}} + (( ${+functions[.zinit-forget-completion]} )) || builtin source ${ZINIT[BIN_DIR]}"/zinit-install.zsh" + .zinit-compinit >/dev/null +} # >>> # # User-exposed functions # -# FUNCTION: -zplg-pager {{{ +# FUNCTION: .zinit-pager <<< # BusyBox less lacks the -X and -i options, so it can use more --zplg-pager() { +.zinit-pager() { setopt LOCAL_OPTIONS EQUALS if [[ ${${:-=less}:A:t} = 'busybox' ]]; then more @@ -690,17 +690,17 @@ ZPLGM[EXTENDED_GLOB]="" less -FRXi fi } -# }}} +# >>> -# FUNCTION: -zplg-self-update {{{ -# Updates Zplugin code (does a git pull). +# FUNCTION: .zinit-self-update <<< +# Updates Zinit code (does a git pull). # # User-action entry point. --zplg-self-update() { +.zinit-self-update() { setopt localoptions extendedglob nokshglob noksharrays noshwordsplit local nl=$'\n' escape=$'\x1b[' local -a lines - ( builtin cd -q "${ZPLGM[BIN_DIR]}" && \ + ( builtin cd -q "${ZINIT[BIN_DIR]}" && \ command git fetch --quiet && \ lines=( ${(f)"$(command git log --color --date=short --pretty=format:'%Cgreen%cd %h %Creset%s %Cred%d%Creset || %b' ..FETCH_HEAD)"} ) if (( ${#lines} > 0 )); then @@ -714,47 +714,48 @@ ZPLGM[EXTENDED_GLOB]="" # Replace what follows "|| ..." with the same thing but with no newlines, # and also only first 10 words (the (w)-flag enables word-indexing) lines=( "${lines[@]/(#b)[[:blank:]]#\|\|(*)(#e)/| ${${match[1]//$nl/ }[(w)1,(w)10]}}" ) - builtin print -rl -- "${lines[@]}" | -zplg-pager + builtin print -rl -- "${lines[@]}" | .zinit-pager fi command git pull --no-stat; ) - builtin print -- "Compiling Zplugin (zcompile)..." - command rm -f "${ZPLGM[BIN_DIR]}"/*.zwc(DN) - zcompile "${ZPLGM[BIN_DIR]}"/zplugin.zsh - zcompile "${ZPLGM[BIN_DIR]}"/zplugin-side.zsh - zcompile "${ZPLGM[BIN_DIR]}"/zplugin-install.zsh - zcompile "${ZPLGM[BIN_DIR]}"/zplugin-autoload.zsh - zcompile "${ZPLGM[BIN_DIR]}"/git-process-output.zsh -} # }}} -# FUNCTION: -zplg-show-registered-plugins {{{ + builtin print -- "Compiling Zinit (zcompile)..." + command rm -f "${ZINIT[BIN_DIR]}"/*.zwc(DN) + zcompile "${ZINIT[BIN_DIR]}"/zinit.zsh + zcompile "${ZINIT[BIN_DIR]}"/zinit-side.zsh + zcompile "${ZINIT[BIN_DIR]}"/zinit-install.zsh + zcompile "${ZINIT[BIN_DIR]}"/zinit-autoload.zsh + zcompile "${ZINIT[BIN_DIR]}"/git-process-output.zsh +} # >>> +# FUNCTION: .zinit-show-registered-plugins <<< # Lists loaded plugins (subcommands list, lodaded). # # User-action entry point. --zplg-show-registered-plugins() { +.zinit-show-registered-plugins() { + emulate -LR zsh + setopt extendedglob warncreateglobal typesetsilent noshortloops + typeset -a filtered local keyword="$1" - -zplg-save-set-extendedglob keyword="${keyword## ##}" keyword="${keyword%% ##}" if [[ -n "$keyword" ]]; then - print "Installed plugins matching ${ZPLGM[col-info]}$keyword${ZPLGM[col-rst]}:" - filtered=( "${(M)ZPLG_REGISTERED_PLUGINS[@]:#*$keyword*}" ) + print "Installed plugins matching ${ZINIT[col-info]}$keyword${ZINIT[col-rst]}:" + filtered=( "${(M)ZINIT_REGISTERED_PLUGINS[@]:#*$keyword*}" ) else - filtered=( "${ZPLG_REGISTERED_PLUGINS[@]}" ) + filtered=( "${ZINIT_REGISTERED_PLUGINS[@]}" ) fi - -zplg-restore-extendedglob local i for i in "${filtered[@]}"; do - [[ "$i" = "_local/zplugin" ]] && continue - -zplg-any-colorify-as-uspl2 "$i" + [[ "$i" = "_local/zinit" ]] && continue + .zinit-any-colorify-as-uspl2 "$i" # Mark light loads - [[ "${ZPLG_REGISTERED_STATES[$i]}" = "1" ]] && REPLY="$REPLY ${ZPLGM[col-info]}*${ZPLGM[col-rst]}" + [[ "${ZINIT_REGISTERED_STATES[$i]}" = "1" ]] && REPLY="$REPLY ${ZINIT[col-info]}*${ZINIT[col-rst]}" print -r -- "$REPLY" done -} # }}} -# FUNCTION: -zplg-unload {{{ +} # >>> +# FUNCTION: .zinit-unload <<< # 0. Call the Zsh Plugin's Standard *_plugin_unload function # 0. Call the code provided by the Zsh Plugin's Standard @zsh-plugin-run-at-update # 1. Delete bindkeys (...) @@ -771,16 +772,16 @@ ZPLGM[EXTENDED_GLOB]="" # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-unload() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-unload() { + .zinit-any-to-user-plugin "$1" "$2" local uspl2="${reply[-2]}${${reply[-2]:#(%|/)*}:+/}${reply[-1]}" user="${reply[-2]}" plugin="${reply[-1]}" quiet="${${3:+1}:-0}" local k - -zplg-any-colorify-as-uspl2 "$uspl2" - (( quiet )) || print -r -- "${ZPLGM[col-bar]}---${ZPLGM[col-rst]} Unloading plugin: $REPLY ${ZPLGM[col-bar]}---${ZPLGM[col-rst]}" + .zinit-any-colorify-as-uspl2 "$uspl2" + (( quiet )) || print -r -- "${ZINIT[col-bar]}---${ZINIT[col-rst]} Unloading plugin: $REPLY ${ZINIT[col-bar]}---${ZINIT[col-rst]}" local __dir - [[ "$user" = "%" ]] && __dir="$plugin" || __dir="${ZPLGM[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" + [[ "$user" = "%" ]] && __dir="$plugin" || __dir="${ZINIT[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" # KSH_ARRAYS immunity integer correct=0 @@ -788,15 +789,15 @@ ZPLGM[EXTENDED_GLOB]="" # Allow unload for debug user if [[ "$uspl2" != "_dtrace/_dtrace" ]]; then - -zplg-exists-message "$1" "$2" || return 1 + .zinit-exists-message "$1" "$2" || return 1 fi - -zplg-any-colorify-as-uspl2 "$1" "$2" + .zinit-any-colorify-as-uspl2 "$1" "$2" local uspl2col="$REPLY" # Store report of the plugin in variable LASTREPORT typeset -g LASTREPORT - LASTREPORT=`-zplg-show-report "$1" "$2"` + LASTREPORT=`.zinit-show-report "$1" "$2"` # # Call the Zsh Plugin's Standard *_plugin_unload function @@ -810,11 +811,11 @@ ZPLGM[EXTENDED_GLOB]="" local -a tmp local -A sice - tmp=( "${(z@)ZPLG_SICE[$uspl2]}" ) + tmp=( "${(z@)ZINIT_SICE[$uspl2]}" ) (( ${#tmp} > 1 && ${#tmp} % 2 == 0 )) && sice=( "${(Q)tmp[@]}" ) || sice=() if [[ -n ${sice[ps-on-unload]} ]]; then - (( quiet )) || print -r "Running plugin's provided unload code: ${ZPLGM[col-info]}${sice[ps-on-unload][1,50]}${sice[ps-on-unload][51]:+…}${ZPLGM[col-rst]}" + (( quiet )) || print -r "Running plugin's provided unload code: ${ZINIT[col-info]}${sice[ps-on-unload][1,50]}${sice[ps-on-unload][51]:+…}${ZINIT[col-rst]}" local __oldcd="$PWD" () { setopt localoptions noautopushd; builtin cd -q "$__dir"; } eval "${sice[ps-on-unload]}" @@ -826,7 +827,7 @@ ZPLGM[EXTENDED_GLOB]="" # typeset -a string_widget - string_widget=( "${(z)ZPLGM[BINDKEYS__$uspl2]}" ) + string_widget=( "${(z)ZINIT[BINDKEYS__$uspl2]}" ) local sw for sw in "${(Oa)string_widget[@]}"; do [[ -z "$sw" ]] && continue @@ -845,26 +846,26 @@ ZPLGM[EXTENDED_GLOB]="" if [[ "$sw_arr4" = "-M" && "$sw_arr6" != "-R" ]]; then if [[ -n "$sw_arr3" ]]; then - (( quiet )) || print -r "Restoring bindkey ${(q)sw_arr1} $sw_arr3 ${ZPLGM[col-info]}in map ${ZPLGM[col-rst]}$sw_arr5" + (( quiet )) || print -r "Restoring bindkey ${(q)sw_arr1} $sw_arr3 ${ZINIT[col-info]}in map ${ZINIT[col-rst]}$sw_arr5" bindkey -M "$sw_arr5" "$sw_arr1" "$sw_arr3" else - (( quiet )) || print -r "Deleting bindkey ${(q)sw_arr1} $sw_arr2 ${ZPLGM[col-info]}in map ${ZPLGM[col-rst]}$sw_arr5" + (( quiet )) || print -r "Deleting bindkey ${(q)sw_arr1} $sw_arr2 ${ZINIT[col-info]}in map ${ZINIT[col-rst]}$sw_arr5" bindkey -M "$sw_arr5" -r "$sw_arr1" fi elif [[ "$sw_arr4" = "-M" && "$sw_arr6" = "-R" ]]; then if [[ -n "$sw_arr3" ]]; then - (( quiet )) || print -r "Restoring ${ZPLGM[col-info]}range${ZPLGM[col-rst]} bindkey ${(q)sw_arr1} $sw_arr3 ${ZPLGM[col-info]}in map ${ZPLGM[col-rst]}$sw_arr5" + (( quiet )) || print -r "Restoring ${ZINIT[col-info]}range${ZINIT[col-rst]} bindkey ${(q)sw_arr1} $sw_arr3 ${ZINIT[col-info]}in map ${ZINIT[col-rst]}$sw_arr5" bindkey -RM "$sw_arr5" "$sw_arr1" "$sw_arr3" else - (( quiet )) || print -r "Deleting ${ZPLGM[col-info]}range${ZPLGM[col-rst]} bindkey ${(q)sw_arr1} $sw_arr2 ${ZPLGM[col-info]}in map ${ZPLGM[col-rst]}$sw_arr5" + (( quiet )) || print -r "Deleting ${ZINIT[col-info]}range${ZINIT[col-rst]} bindkey ${(q)sw_arr1} $sw_arr2 ${ZINIT[col-info]}in map ${ZINIT[col-rst]}$sw_arr5" bindkey -M "$sw_arr5" -Rr "$sw_arr1" fi elif [[ "$sw_arr4" != "-M" && "$sw_arr6" = "-R" ]]; then if [[ -n "$sw_arr3" ]]; then - (( quiet )) || print -r "Restoring ${ZPLGM[col-info]}range${ZPLGM[col-rst]} bindkey ${(q)sw_arr1} $sw_arr3" + (( quiet )) || print -r "Restoring ${ZINIT[col-info]}range${ZINIT[col-rst]} bindkey ${(q)sw_arr1} $sw_arr3" bindkey -R "$sw_arr1" "$sw_arr3" else - (( quiet )) || print -r "Deleting ${ZPLGM[col-info]}range${ZPLGM[col-rst]} bindkey ${(q)sw_arr1} $sw_arr2" + (( quiet )) || print -r "Deleting ${ZINIT[col-info]}range${ZINIT[col-rst]} bindkey ${(q)sw_arr1} $sw_arr2" bindkey -Rr "$sw_arr1" fi elif [[ "$sw_arr4" = "-A" ]]; then @@ -889,7 +890,7 @@ ZPLGM[EXTENDED_GLOB]="" # typeset -a pattern_style - pattern_style=( "${(z)ZPLGM[ZSTYLES__$uspl2]}" ) + pattern_style=( "${(z)ZINIT[ZSTYLES__$uspl2]}" ) local ps for ps in "${(Oa)pattern_style[@]}"; do [[ -z "$ps" ]] && continue @@ -912,15 +913,15 @@ ZPLGM[EXTENDED_GLOB]="" # # Paranoid, don't want bad key/value pair error - -zplg-diff-options-compute "$uspl2" + .zinit-diff-options-compute "$uspl2" integer empty=0 - -zplg-save-set-extendedglob - [[ "${ZPLGM[OPTIONS__$uspl2]}" != *[$'! \t']* ]] && empty=1 - -zplg-restore-extendedglob + .zinit-save-set-extendedglob + [[ "${ZINIT[OPTIONS__$uspl2]}" != *[$'! \t']* ]] && empty=1 + .zinit-restore-extendedglob if (( empty != 1 )); then typeset -A opts - opts=( "${(z)ZPLGM[OPTIONS__$uspl2]}" ) + opts=( "${(z)ZINIT[OPTIONS__$uspl2]}" ) for k in "${(kon)opts[@]}"; do # Internal options [[ "$k" = "physical" ]] && continue @@ -940,7 +941,7 @@ ZPLGM[EXTENDED_GLOB]="" # typeset -a aname_avalue - aname_avalue=( "${(z)ZPLGM[ALIASES__$uspl2]}" ) + aname_avalue=( "${(z)ZINIT[ALIASES__$uspl2]}" ) local nv for nv in "${(Oa)aname_avalue[@]}"; do [[ -z "$nv" ]] && continue @@ -956,23 +957,23 @@ ZPLGM[EXTENDED_GLOB]="" if [[ "$nv_arr3" = "-s" ]]; then if [[ -n "$nv_arr2" ]]; then - (( quiet )) || print "Restoring ${ZPLGM[col-info]}suffix${ZPLGM[col-rst]} alias ${nv_arr1}=${nv_arr2}" + (( quiet )) || print "Restoring ${ZINIT[col-info]}suffix${ZINIT[col-rst]} alias ${nv_arr1}=${nv_arr2}" alias "$nv_arr1" &> /dev/null && unalias -s -- "$nv_arr1" alias -s -- "${nv_arr1}=${nv_arr2}" else (( quiet )) || alias "$nv_arr1" &> /dev/null && { - print "Removing ${ZPLGM[col-info]}suffix${ZPLGM[col-rst]} alias ${nv_arr1}" + print "Removing ${ZINIT[col-info]}suffix${ZINIT[col-rst]} alias ${nv_arr1}" unalias -s -- "$nv_arr1" } fi elif [[ "$nv_arr3" = "-g" ]]; then if [[ -n "$nv_arr2" ]]; then - (( quiet )) || print "Restoring ${ZPLGM[col-info]}global${ZPLGM[col-rst]} alias ${nv_arr1}=${nv_arr2}" + (( quiet )) || print "Restoring ${ZINIT[col-info]}global${ZINIT[col-rst]} alias ${nv_arr1}=${nv_arr2}" alias "$nv_arr1" &> /dev/null && unalias -g -- "$nv_arr1" alias -g -- "${nv_arr1}=${nv_arr2}" else (( quiet )) || alias "$nv_arr1" &> /dev/null && { - print "Removing ${ZPLGM[col-info]}global${ZPLGM[col-rst]} alias ${nv_arr1}" + print "Removing ${ZINIT[col-info]}global${ZINIT[col-rst]} alias ${nv_arr1}" unalias -- "${(q)nv_arr1}" } fi @@ -995,13 +996,13 @@ ZPLGM[EXTENDED_GLOB]="" # local -a keys - keys=( "${(@on)ZPLGM[(I)TIME_<->_*]}" ) + keys=( "${(@on)ZINIT[(I)TIME_<->_*]}" ) integer keys_size=${#keys} () { setopt localoptions extendedglob noksharrays typesetsilent typeset -a restore_widgets skip_delete local wid - restore_widgets=( "${(z)ZPLGM[WIDGETS_SAVED__$uspl2]}" ) + restore_widgets=( "${(z)ZINIT[WIDGETS_SAVED__$uspl2]}" ) for wid in "${(Oa)restore_widgets[@]}"; do [[ -z "$wid" ]] && continue wid="${(Q)wid}" @@ -1024,7 +1025,7 @@ ZPLGM[EXTENDED_GLOB]="" local oth_uspl2="" [[ "$found_time_key" = (#b)TIME_${idx}_(*) ]] && oth_uspl2="${match[1]//---//}" local -a entry_splitted - entry_splitted=( "${(z@)ZPLGM[WIDGETS_SAVED__$oth_uspl2]}" ) + entry_splitted=( "${(z@)ZINIT[WIDGETS_SAVED__$oth_uspl2]}" ) integer found_idx="${entry_splitted[(I)(-N|-C)\ $orig_saved1\\\ *]}" if (( found_idx )) then @@ -1050,7 +1051,7 @@ ZPLGM[EXTENDED_GLOB]="" # plugin's function at any moment oth_orig_saved[5]="${(q)orig_saved3}" # chain up the widget entry_splitted[found_idx]="${(q)${(j: :)oth_orig_saved}}" - ZPLGM[WIDGETS_SAVED__$oth_uspl2]="${(j: :)entry_splitted}" + ZINIT[WIDGETS_SAVED__$oth_uspl2]="${(j: :)entry_splitted}" integer idx="${functions[$orig_saved2][(i)(#b)([^\{[:space:]]#$orig_saved1[^\{[:space:]])#]}" if (( idx <= ${#functions[$orig_saved2]} )) then @@ -1091,7 +1092,7 @@ ZPLGM[EXTENDED_GLOB]="" } typeset -a delete_widgets - delete_widgets=( "${(z)ZPLGM[WIDGETS_DELETE__$uspl2]}" ) + delete_widgets=( "${(z)ZINIT[WIDGETS_DELETE__$uspl2]}" ) local wid for wid in "${(Oa)delete_widgets[@]}"; do [[ -z "$wid" ]] && continue @@ -1100,7 +1101,7 @@ ZPLGM[EXTENDED_GLOB]="" print "Would delete $wid" continue fi - if [[ "${ZPLG_ZLE_HOOKS_LIST[$wid]}" = "1" ]]; then + if [[ "${ZINIT_ZLE_HOOKS_LIST[$wid]}" = "1" ]]; then (( quiet )) || print "Removing Zle hook \`$wid'" else (( quiet )) || print "Removing Zle widget \`$wid'" @@ -1112,9 +1113,9 @@ ZPLGM[EXTENDED_GLOB]="" # 6. Unfunction # - -zplg-diff-functions-compute "$uspl2" + .zinit-diff-functions-compute "$uspl2" typeset -a func - func=( "${(z)ZPLGM[FUNCTIONS__$uspl2]}" ) + func=( "${(z)ZINIT[FUNCTIONS__$uspl2]}" ) local f for f in "${(on)func[@]}"; do [[ -z "$f" ]] && continue @@ -1133,27 +1134,27 @@ ZPLGM[EXTENDED_GLOB]="" # 7. Clean up FPATH and PATH # - -zplg-diff-env-compute "$uspl2" + .zinit-diff-env-compute "$uspl2" # Have to iterate over $path elements and # skip those that were added by the plugin typeset -a new elem p - elem=( "${(z)ZPLGM[PATH__$uspl2]}" ) + elem=( "${(z)ZINIT[PATH__$uspl2]}" ) for p in "${path[@]}"; do [[ -z "${elem[(r)${(q)p}]}" ]] && { new+=( "$p" ); } || { - (( quiet )) || print "Removing PATH element ${ZPLGM[col-info]}$p${ZPLGM[col-rst]}" - [[ -d "$p" ]] || (( quiet )) || print "${ZPLGM[col-error]}Warning:${ZPLGM[col-rst]} it didn't exist on disk" + (( quiet )) || print "Removing PATH element ${ZINIT[col-info]}$p${ZINIT[col-rst]}" + [[ -d "$p" ]] || (( quiet )) || print "${ZINIT[col-error]}Warning:${ZINIT[col-rst]} it didn't exist on disk" } done path=( "${new[@]}" ) # The same for $fpath - elem=( "${(z)ZPLGM[FPATH__$uspl2]}" ) + elem=( "${(z)ZINIT[FPATH__$uspl2]}" ) new=( ) for p in "${fpath[@]}"; do [[ -z "${elem[(r)${(q)p}]}" ]] && { new+=( "$p" ); } || { - (( quiet )) || print "Removing FPATH element ${ZPLGM[col-info]}$p${ZPLGM[col-rst]}" - [[ -d "$p" ]] || (( quiet )) || print "${ZPLGM[col-error]}Warning:${ZPLGM[col-rst]} it didn't exist on disk" + (( quiet )) || print "Removing FPATH element ${ZINIT[col-info]}$p${ZINIT[col-rst]}" + [[ -d "$p" ]] || (( quiet )) || print "${ZINIT[col-error]}Warning:${ZINIT[col-rst]} it didn't exist on disk" } done fpath=( "${new[@]}" ) @@ -1162,21 +1163,21 @@ ZPLGM[EXTENDED_GLOB]="" # 8. Delete created variables # - -zplg-diff-parameter-compute "$uspl2" + .zinit-diff-parameter-compute "$uspl2" empty=0 - -zplg-save-set-extendedglob - [[ "${ZPLGM[PARAMETERS_POST__$uspl2]}" != *[$'! \t']* ]] && empty=1 - -zplg-restore-extendedglob + .zinit-save-set-extendedglob + [[ "${ZINIT[PARAMETERS_POST__$uspl2]}" != *[$'! \t']* ]] && empty=1 + .zinit-restore-extendedglob if (( empty != 1 )); then typeset -A elem_pre elem_post - elem_pre=( "${(z)ZPLGM[PARAMETERS_PRE__$uspl2]}" ) - elem_post=( "${(z)ZPLGM[PARAMETERS_POST__$uspl2]}" ) + elem_pre=( "${(z)ZINIT[PARAMETERS_PRE__$uspl2]}" ) + elem_post=( "${(z)ZINIT[PARAMETERS_POST__$uspl2]}" ) # Find variables created or modified local wl found local -a whitelist - whitelist=( "${(@Q)${(z@)ZPLGM[ENV-WHITELIST]}}" ) + whitelist=( "${(@Q)${(z@)ZINIT[ENV-WHITELIST]}}" ) for k in "${(k)elem_post[@]}"; do k="${(Q)k}" local v1="${(Q)elem_pre[$k]}" @@ -1228,94 +1229,94 @@ ZPLGM[EXTENDED_GLOB]="" # if [[ "$uspl2" = "_dtrace/_dtrace" ]]; then - -zplg-clear-debug-report + .zinit-clear-debug-report (( quiet )) || print "dtrace report saved to \$LASTREPORT" else (( quiet )) || print "Unregistering plugin $uspl2col" - -zplg-unregister-plugin "$user" "$plugin" "${sice[teleid]}" + .zinit-unregister-plugin "$user" "$plugin" "${sice[teleid]}" zsh_loaded_plugins[${zsh_loaded_plugins[(i)$user${${user:#(%|/)*}:+/}$plugin]}]=() # Support Zsh plugin standard - -zplg-clear-report-for "$user" "$plugin" + .zinit-clear-report-for "$user" "$plugin" (( quiet )) || print "Plugin's report saved to \$LASTREPORT" fi -} # }}} -# FUNCTION: -zplg-show-report {{{ +} # >>> +# FUNCTION: .zinit-show-report <<< # Displays report of the plugin given. # # User-action entry point. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user (+ plugin in $2), plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-show-report() { +.zinit-show-report() { setopt localoptions extendedglob warncreateglobal typesetsilent noksharrays - -zplg-any-to-user-plugin "$1" "$2" + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" uspl2="${reply[-2]}${${reply[-2]:#(%|/)*}:+/}${reply[-1]}" # Allow debug report if [[ "$user/$plugin" != "_dtrace/_dtrace" ]]; then - -zplg-exists-message "$user" "$plugin" || return 1 + .zinit-exists-message "$user" "$plugin" || return 1 fi # Print title - printf "${ZPLGM[col-title]}Report for${ZPLGM[col-rst]} %s%s plugin\n"\ - "${user:+${ZPLGM[col-uname]}$user${ZPLGM[col-rst]}}${${user:#(%|/)*}:+/}"\ - "${ZPLGM[col-pname]}$plugin${ZPLGM[col-rst]}" + printf "${ZINIT[col-title]}Report for${ZINIT[col-rst]} %s%s plugin\n"\ + "${user:+${ZINIT[col-uname]}$user${ZINIT[col-rst]}}${${user:#(%|/)*}:+/}"\ + "${ZINIT[col-pname]}$plugin${ZINIT[col-rst]}" # Print "----------" local msg="Report for $user${${user:#(%|/)*}:+/}$plugin plugin" - print -- "${ZPLGM[col-bar]}${(r:${#msg}::-:)tmp__}${ZPLGM[col-rst]}" + print -- "${ZINIT[col-bar]}${(r:${#msg}::-:)tmp__}${ZINIT[col-rst]}" local -A map map=( - Error: "${ZPLGM[col-error]}" - Warning: "${ZPLGM[col-error]}" - Note: "${ZPLGM[col-note]}" + Error: "${ZINIT[col-error]}" + Warning: "${ZINIT[col-error]}" + Note: "${ZINIT[col-note]}" ) # Print report gathered via shadowing () { setopt localoptions extendedglob - print -rl -- "${(@)${(f@)ZPLG_REPORTS[$uspl2]}/(#b)(#s)([^[:space:]]##)([[:space:]]##)/${map[${match[1]}]:-${ZPLGM[col-keyword]}}${match[1]}${ZPLGM[col-rst]}${match[2]}}" + print -rl -- "${(@)${(f@)ZINIT_REPORTS[$uspl2]}/(#b)(#s)([^[:space:]]##)([[:space:]]##)/${map[${match[1]}]:-${ZINIT[col-keyword]}}${match[1]}${ZINIT[col-rst]}${match[2]}}" } # Print report gathered via $functions-diffing REPLY="" - -zplg-diff-functions-compute "$uspl2" - -zplg-format-functions "$uspl2" - [[ -n "$REPLY" ]] && print "${ZPLGM[col-p]}Functions created:${ZPLGM[col-rst]}"$'\n'"$REPLY" + .zinit-diff-functions-compute "$uspl2" + .zinit-format-functions "$uspl2" + [[ -n "$REPLY" ]] && print "${ZINIT[col-p]}Functions created:${ZINIT[col-rst]}"$'\n'"$REPLY" # Print report gathered via $options-diffing REPLY="" - -zplg-diff-options-compute "$uspl2" - -zplg-format-options "$uspl2" - [[ -n "$REPLY" ]] && print "${ZPLGM[col-p]}Options changed:${ZPLGM[col-rst]}"$'\n'"$REPLY" + .zinit-diff-options-compute "$uspl2" + .zinit-format-options "$uspl2" + [[ -n "$REPLY" ]] && print "${ZINIT[col-p]}Options changed:${ZINIT[col-rst]}"$'\n'"$REPLY" # Print report gathered via environment diffing REPLY="" - -zplg-diff-env-compute "$uspl2" - -zplg-format-env "$uspl2" "1" - [[ -n "$REPLY" ]] && print "${ZPLGM[col-p]}PATH elements added:${ZPLGM[col-rst]}"$'\n'"$REPLY" + .zinit-diff-env-compute "$uspl2" + .zinit-format-env "$uspl2" "1" + [[ -n "$REPLY" ]] && print "${ZINIT[col-p]}PATH elements added:${ZINIT[col-rst]}"$'\n'"$REPLY" REPLY="" - -zplg-format-env "$uspl2" "2" - [[ -n "$REPLY" ]] && print "${ZPLGM[col-p]}FPATH elements added:${ZPLGM[col-rst]}"$'\n'"$REPLY" + .zinit-format-env "$uspl2" "2" + [[ -n "$REPLY" ]] && print "${ZINIT[col-p]}FPATH elements added:${ZINIT[col-rst]}"$'\n'"$REPLY" # Print report gathered via parameter diffing - -zplg-diff-parameter-compute "$uspl2" - -zplg-format-parameter "$uspl2" - [[ -n "$REPLY" ]] && print "${ZPLGM[col-p]}Variables added or redefined:${ZPLGM[col-rst]}"$'\n'"$REPLY" + .zinit-diff-parameter-compute "$uspl2" + .zinit-format-parameter "$uspl2" + [[ -n "$REPLY" ]] && print "${ZINIT[col-p]}Variables added or redefined:${ZINIT[col-rst]}"$'\n'"$REPLY" # Print what completions plugin has - -zplg-find-completions-of-plugin "$user" "$plugin" + .zinit-find-completions-of-plugin "$user" "$plugin" typeset -a completions completions=( "${reply[@]}" ) if [[ "${#completions[@]}" -ge "1" ]]; then - print "${ZPLGM[col-p]}Completions:${ZPLGM[col-rst]}" - -zplg-check-which-completions-are-installed "${completions[@]}" + print "${ZINIT[col-p]}Completions:${ZINIT[col-rst]}" + .zinit-check-which-completions-are-installed "${completions[@]}" typeset -a installed installed=( "${reply[@]}" ) - -zplg-check-which-completions-are-enabled "${completions[@]}" + .zinit-check-which-completions-are-enabled "${completions[@]}" typeset -a enabled enabled=( "${reply[@]}" ) @@ -1323,38 +1324,38 @@ ZPLGM[EXTENDED_GLOB]="" for (( idx=1; idx <= count; idx ++ )); do print -n "${completions[idx]:t}" if [[ "${installed[idx]}" != "1" ]]; then - print -n " ${ZPLGM[col-uninst]}[not installed]${ZPLGM[col-rst]}" + print -n " ${ZINIT[col-uninst]}[not installed]${ZINIT[col-rst]}" else if [[ "${enabled[idx]}" = "1" ]]; then - print -n " ${ZPLGM[col-info]}[enabled]${ZPLGM[col-rst]}" + print -n " ${ZINIT[col-info]}[enabled]${ZINIT[col-rst]}" else - print -n " ${ZPLGM[col-error]}[disabled]${ZPLGM[col-rst]}" + print -n " ${ZINIT[col-error]}[disabled]${ZINIT[col-rst]}" fi fi print done print fi -} # }}} -# FUNCTION: -zplg-show-all-reports {{{ +} # >>> +# FUNCTION: .zinit-show-all-reports <<< # Displays reports of all loaded plugins. # # User-action entry point. --zplg-show-all-reports() { +.zinit-show-all-reports() { local i - for i in "${ZPLG_REGISTERED_PLUGINS[@]}"; do - [[ "$i" = "_local/zplugin" ]] && continue - -zplg-show-report "$i" + for i in "${ZINIT_REGISTERED_PLUGINS[@]}"; do + [[ "$i" = "_local/zinit" ]] && continue + .zinit-show-report "$i" done -} # }}} -# FUNCTION: -zplg-show-debug-report {{{ +} # >>> +# FUNCTION: .zinit-show-debug-report <<< # Displays dtrace report (data recorded in interactive session). # # User-action entry point. --zplg-show-debug-report() { - -zplg-show-report "_dtrace/_dtrace" -} # }}} -# FUNCTION: -zplg-update-or-status {{{ +.zinit-show-debug-report() { + .zinit-show-report "_dtrace/_dtrace" +} # >>> +# FUNCTION: .zinit-update-or-status <<< # Updates (git pull) or does `git status' for given plugin. # # User-action entry point. @@ -1362,54 +1363,54 @@ ZPLGM[EXTENDED_GLOB]="" # $1 - "status" for status, other for update # $2 - plugin spec (4 formats: user---plugin, user/plugin, user (+ plugin in $2), plugin) # $3 - plugin (only when $1 - i.e. user - given) --zplg-update-or-status() { +.zinit-update-or-status() { emulate -LR zsh setopt extendedglob nullglob warncreateglobal typesetsilent noshortloops local -a arr - -zplg-two-paths "$2${${2:#(%|/)*}:+${3:+/}}$3" + .zinit-two-paths "$2${${2:#(%|/)*}:+${3:+/}}$3" if [[ -d "${reply[-4]}" || -d "${reply[-2]}" ]]; then - -zplg-update-or-status-snippet "$1" "$2" "$3" + .zinit-update-or-status-snippet "$1" "$2" "$3" return $? fi - -zplg-any-to-user-plugin "$2" "$3" + .zinit-any-to-user-plugin "$2" "$3" local user="${reply[-2]}" plugin="${reply[-1]}" st="$1" \ local_dir filename is_snippet key \ id_as="${reply[-2]}${${reply[-2]:#(%|/)*}:+/}${reply[-1]}" local -A ice - -zplg-exists-physically-message "$user" "$plugin" || return 1 + .zinit-exists-physically-message "$user" "$plugin" || return 1 if [[ "$st" = "status" ]]; then - ( builtin cd -q "${ZPLGM[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}"; command git status; ) + ( builtin cd -q "${ZINIT[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}"; command git status; ) return 0 fi - (( ${#ZPLG_ICE[@]} > 0 )) && { ZPLG_SICE[$user/$plugin]=""; local nf="-nftid"; } + (( ${#ZINIT_ICE[@]} > 0 )) && { ZINIT_SICE[$user/$plugin]=""; local nf="-nftid"; } - -zplg-compute-ice "$user${${user:#(%|/)*}:+/}$plugin" "pack$nf" \ + .zinit-compute-ice "$user${${user:#(%|/)*}:+/}$plugin" "pack$nf" \ ice local_dir filename is_snippet || return 1 [[ "${ice[teleid]:-$id_as}" = (#b)([^/]##)/(*) ]] && { user="${match[1]}"; plugin="${match[2]}"; } || { user=""; plugin="${ice[teleid]:-$id_as}"; } - -zplg-any-to-user-plugin ${ice[teleid]:-$id_as} + .zinit-any-to-user-plugin ${ice[teleid]:-$id_as} local -a arr - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:preinit <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:preinit <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" plugin "${reply[-2]}" "${reply[-1]}" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}}" preinit || \ + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" plugin "${reply[-2]}" "${reply[-1]}" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZINIT[PLUGINS_DIR]}/${id_as//\//---}}" preinit || \ return $(( 10 - $? )) done # Check if repository has a remote set, if it is _local - local repo="${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}" + local repo="${ZINIT[PLUGINS_DIR]}/${id_as//\//---}" if [[ -f "$repo/.git/config" ]]; then local -a config config=( ${(f)"$(<$repo/.git/config)"} ) if [[ ${#${(M)config[@]:#\[remote[[:blank:]]*\]}} -eq 0 ]]; then [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && { - -zplg-any-colorify-as-uspl2 "$id_as" + .zinit-any-colorify-as-uspl2 "$id_as" [[ "$id_as" = _local/* ]] && print -r -- "Skipping local plugin $REPLY" || \ print -r -- "$REPLY doesn't have a remote set, will not fetch" } @@ -1417,7 +1418,7 @@ ZPLGM[EXTENDED_GLOB]="" fi fi - command rm -f $local_dir/.zplugin_lstupd + command rm -f $local_dir/.zinit_lastupd if (( 1 )); then if [[ -z "${ice[is_release]}" && "${ice[from]}" = (gh-r|github-rel) ]]; then @@ -1425,8 +1426,8 @@ ZPLGM[EXTENDED_GLOB]="" fi local do_update=0 skip_pull=0 if [[ -n "${ice[is_release]}" ]] { - (( ${+functions[-zplg-setup-plugin-dir]} )) || builtin source ${ZPLGM[BIN_DIR]}"/zplugin-install.zsh" - -zplg-get-latest-gh-r-version "$user" "$plugin" + (( ${+functions[.zinit-setup-plugin-dir]} )) || builtin source ${ZINIT[BIN_DIR]}"/zinit-install.zsh" + .zinit-get-latest-gh-r-version "$user" "$plugin" local version=$REPLY if [[ ${ice[is_release]} = */$version/* ]] { (( !ICE_OPTS[opt_-q,--quiet] )) && \ @@ -1442,35 +1443,35 @@ ZPLGM[EXTENDED_GLOB]="" [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print "Removing the previous file(s) (-r/--reset given)..." command rm -rf "${local_dir:-/tmp/xyzabc312}"/*(ND) } - ZPLG_ICE=( "${(kv)ice[@]}" ) + ZINIT_ICE=( "${(kv)ice[@]}" ) # Run annexes' atpull hooks (the before atpull-ice ones) [[ ${+ice[atpull]} = 1 && ${ice[atpull]} = "!"* ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "plugin" "$user" "$plugin" "$id_as" "$local_dir" \!atpull done } - (( !skip_pull && ${+ZPLG_ICE[reset]} )) && ( - [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZPLG_ICE[reset]:-rm -rf ${local_dir:-/tmp/xyzabc312}/*}%f" - eval ${ZPLG_ICE[reset]:-command rm -rf "${local_dir:-/tmp/xyzabc312}"/*(ND)} + (( !skip_pull && ${+ZINIT_ICE[reset]} )) && ( + [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZINIT_ICE[reset]:-rm -rf ${local_dir:-/tmp/xyzabc312}/*}%f" + eval ${ZINIT_ICE[reset]:-command rm -rf "${local_dir:-/tmp/xyzabc312}"/*(ND)} ) - [[ ${ice[atpull]} = "!"* ]] && -zplg-countdown "atpull" && ( (( ${+ice[nocd]} == 0 )) && { builtin cd -q "$local_dir" && -zplg-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ((1)); } || -zplg-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ) - print -r -- "" >! "$local_dir/.zplugin_lstupd" + [[ ${ice[atpull]} = "!"* ]] && .zinit-countdown "atpull" && ( (( ${+ice[nocd]} == 0 )) && { builtin cd -q "$local_dir" && .zinit-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ((1)); } || .zinit-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ) + print -r -- "" >! "$local_dir/.zinit_lastupd" if (( !skip_pull )) { if [[ "${ICE_OPTS[opt_-q,--quiet]}" = 1 ]] { - -zplg-any-colorify-as-uspl2 "$id_as" + .zinit-any-colorify-as-uspl2 "$id_as" print "\nUpdating plugin $REPLY" } - -zplg-setup-plugin-dir "$user" "$plugin" "$id_as" release -u $version + .zinit-setup-plugin-dir "$user" "$plugin" "$id_as" release -u $version if (( ICE_OPTS[opt_-q,--quiet] != 1 )) { print } } - ZPLG_ICE=() + ZINIT_ICE=() } } else { ( builtin cd -q "$local_dir" || return 1 @@ -1483,29 +1484,29 @@ ZPLGM[EXTENDED_GLOB]="" [[ $had_output -eq 0 ]] && { had_output=1 if [[ "${ICE_OPTS[opt_-q,--quiet]}" = 1 ]] { - -zplg-any-colorify-as-uspl2 "$id_as" + .zinit-any-colorify-as-uspl2 "$id_as" print "\r\nUpdating plugin $REPLY" } } print $line } done | \ - command tee .zplugin_lstupd | \ - -zplg-pager & + command tee .zinit_lastupd | \ + .zinit-pager & integer pager_pid=$! { sleep 20 && kill -9 $pager_pid 2>/dev/null 1>&2; } &! { wait $pager_pid; } > /dev/null 2>&1 local -a log - { log=( ${(@f)"$(<$local_dir/.zplugin_lstupd)"} ); } 2>/dev/null + { log=( ${(@f)"$(<$local_dir/.zinit_lastupd)"} ); } 2>/dev/null [[ ${#log} -gt 0 ]] && do_update=1 || \ { skip_pull=1 (( ${+ice[run-atpull]} )) && { do_update=1 - print -r -- "" >! "$local_dir/.zplugin_lstupd" + print -r -- "" >! "$local_dir/.zinit_lastupd" } } @@ -1514,21 +1515,21 @@ ZPLGM[EXTENDED_GLOB]="" [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print "Resetting the repository (-r/--reset given)..." command git reset --hard HEAD } - ZPLG_ICE=( "${(kv)ice[@]}" ) + ZINIT_ICE=( "${(kv)ice[@]}" ) # Run annexes' atpull hooks (the before atpull-ice ones) [[ ${+ice[atpull]} = 1 && ${ice[atpull]} = "!"* ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "plugin" "$user" "$plugin" "$id_as" "$local_dir" \!atpull done } - (( ${+ZPLG_ICE[reset]} )) && ( - [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZPLG_ICE[reset]:-git reset --hard HEAD}%f" - eval "${ZPLG_ICE[reset]:-command git reset --hard HEAD}" + (( ${+ZINIT_ICE[reset]} )) && ( + [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZINIT_ICE[reset]:-git reset --hard HEAD}%f" + eval "${ZINIT_ICE[reset]:-command git reset --hard HEAD}" ) - [[ ${ice[atpull]} = "!"* ]] && -zplg-countdown "atpull" && ( (( ${+ice[nocd]} == 0 )) && { builtin cd -q "$local_dir" && -zplg-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ((1)); } || -zplg-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ) - ZPLG_ICE=() + [[ ${ice[atpull]} = "!"* ]] && .zinit-countdown "atpull" && ( (( ${+ice[nocd]} == 0 )) && { builtin cd -q "$local_dir" && .zinit-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ((1)); } || .zinit-at-eval "${ice[atpull]#\!}" "${ice[atclone]}"; ) + ZINIT_ICE=() (( !skip_pull )) && command git pull --no-stat if (( ICE_OPTS[opt_-q,--quiet] != 1 )) { print @@ -1548,13 +1549,13 @@ ZPLGM[EXTENDED_GLOB]="" ) local -a log - { log=( ${(@f)"$(<$local_dir/.zplugin_lstupd)"} ); } 2>/dev/null + { log=( ${(@f)"$(<$local_dir/.zinit_lastupd)"} ); } 2>/dev/null - command rm -f $local_dir/.zplugin_lstupd + command rm -f $local_dir/.zinit_lastupd # Any new commits? [[ ${#log} -gt 0 ]] && { - [[ ${+ice[make]} = 1 && ${ice[make]} = "!!"* ]] && -zplg-countdown make && { command make -C "$local_dir" ${(@s; ;)${ice[make]#\!\!}}; } + [[ ${+ice[make]} = 1 && ${ice[make]} = "!!"* ]] && .zinit-countdown make && { command make -C "$local_dir" ${(@s; ;)${ice[make]#\!\!}}; } if [[ -z "${ice[is_release]}" && -n "${ice[mv]}" ]]; then if [[ ${ice[mv]} = *("->"|"β†’")* ]] { @@ -1598,135 +1599,135 @@ ZPLGM[EXTENDED_GLOB]="" ) fi - ZPLG_ICE=( "${(kv)ice[@]}" ) + ZINIT_ICE=( "${(kv)ice[@]}" ) # Run annexes' atpull hooks (the before atpull-ice ones) [[ ${ice[atpull]} != "!"* ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "plugin" "$user" "$plugin" "$id_as" "$local_dir" \!atpull done } - [[ ${+ice[make]} = 1 && ${ice[make]} = ("!"[^\!]*|"!") ]] && -zplg-countdown make && { command make -C "$local_dir" ${(@s; ;)${ice[make]#\!}}; } - [[ -n ${ice[atpull]} && ${ice[atpull][1]} != "!" ]] && -zplg-countdown "atpull" && ( (( ${+ice[nocd]} == 0 )) && { builtin cd -q "$local_dir" && -zplg-at-eval "${ice[atpull]}" "${ice[atclone]}"; ((1)); } || -zplg-at-eval "${ice[atpull]}" "${ice[atclone]}"; ) - [[ ${+ice[make]} = 1 && ${ice[make]} != "!"* ]] && -zplg-countdown make && command make -C "$local_dir" ${(@s; ;)${ice[make]}} + [[ ${+ice[make]} = 1 && ${ice[make]} = ("!"[^\!]*|"!") ]] && .zinit-countdown make && { command make -C "$local_dir" ${(@s; ;)${ice[make]#\!}}; } + [[ -n ${ice[atpull]} && ${ice[atpull][1]} != "!" ]] && .zinit-countdown "atpull" && ( (( ${+ice[nocd]} == 0 )) && { builtin cd -q "$local_dir" && .zinit-at-eval "${ice[atpull]}" "${ice[atclone]}"; ((1)); } || .zinit-at-eval "${ice[atpull]}" "${ice[atclone]}"; ) + [[ ${+ice[make]} = 1 && ${ice[make]} != "!"* ]] && .zinit-countdown make && command make -C "$local_dir" ${(@s; ;)${ice[make]}} # Run annexes' atpull hooks (the after atpull-ice ones) - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atpull <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "plugin" "$user" "$plugin" "$id_as" "$local_dir" atpull done - ZPLG_ICE=() + ZINIT_ICE=() } # Store ices to disk at update of plugin - -zplg-store-ices "$local_dir/._zplugin" ice "" "" "" "" + .zinit-store-ices "$local_dir/._zinit" ice "" "" "" "" fi - ZPLG_ICE=( "${(kv)ice[@]}" ) + ZINIT_ICE=( "${(kv)ice[@]}" ) # Run annexes' atpull hooks (the `always' after atpull-ice ones) - reply=( ${(@on)ZPLG_EXTS[(I)z-annex hook:%atpull <->]} ) + reply=( ${(@on)ZINIT_EXTS[(I)z-annex hook:%atpull <->]} ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "plugin" "$user" "$plugin" "$id_as" "$local_dir" \%atpull done - if [[ -n ${ZPLG_ICE[ps-on-update]} ]]; then + if [[ -n ${ZINIT_ICE[ps-on-update]} ]]; then if (( !ICE_OPTS[opt_-q,--quiet] )) { - print -r "Running plugin's provided update code: ${ZPLGM[col-info]}${ZPLG_ICE[ps-on-update][1,50]}${ZPLG_ICE[ps-on-update][51]:+…}${ZPLGM[col-rst]}" + print -r "Running plugin's provided update code: ${ZINIT[col-info]}${ZINIT_ICE[ps-on-update][1,50]}${ZINIT_ICE[ps-on-update][51]:+…}${ZINIT[col-rst]}" ( builtin cd -q "$local_dir" - eval "${ZPLG_ICE[ps-on-update]}" + eval "${ZINIT_ICE[ps-on-update]}" ) } else { ( builtin cd -q "$local_dir" - eval "${ZPLG_ICE[ps-on-update]}" &> /dev/null + eval "${ZINIT_ICE[ps-on-update]}" &> /dev/null ) } fi - ZPLG_ICE=() + ZINIT_ICE=() return 0 -} # }}} -# FUNCTION: -zplg-update-or-status-snippet {{{ +} # >>> +# FUNCTION: .zinit-update-or-status-snippet <<< # # Implements update or status operation for snippet given by URL. # # $1 - "status" or "update" # $2 - snippet URL --zplg-update-or-status-snippet() { +.zinit-update-or-status-snippet() { local st="$1" URL="${2%/}" local_dir filename is_snippet - (( ${#ZPLG_ICE[@]} > 0 )) && { ZPLG_SICE[$URL]=""; local nf="-nf"; } - -zplg-compute-ice "$URL" "pack$nf" \ - ZPLG_ICE local_dir filename is_snippet || return 1 + (( ${#ZINIT_ICE[@]} > 0 )) && { ZINIT_SICE[$URL]=""; local nf="-nf"; } + .zinit-compute-ice "$URL" "pack$nf" \ + ZINIT_ICE local_dir filename is_snippet || return 1 if [[ "$st" = "status" ]]; then - if (( ${+ZPLG_ICE[svn]} )); then - print -r -- "${ZPLGM[col-info]}Status for ${${${local_dir:h}:t}##*--}/${local_dir:t}${ZPLGM[col-rst]}" + if (( ${+ZINIT_ICE[svn]} )); then + print -r -- "${ZINIT[col-info]}Status for ${${${local_dir:h}:t}##*--}/${local_dir:t}${ZINIT[col-rst]}" ( builtin cd -q "$local_dir"; command svn status -vu ) print else - print -r -- "${ZPLGM[col-info]}Status for ${${local_dir:h}##*--}/$filename${ZPLGM[col-rst]}" + print -r -- "${ZINIT[col-info]}Status for ${${local_dir:h}##*--}/$filename${ZINIT[col-rst]}" ( builtin cd -q "$local_dir"; command ls -lth $filename ) print fi else - -zplg-load-snippet "${ZPLG_ICE[teleid]:-$URL}" "-i" "-u" + .zinit-load-snippet "${ZINIT_ICE[teleid]:-$URL}" "-i" "-u" fi - ZPLG_ICE=() + ZINIT_ICE=() } -# }}} -# FUNCTION: -zplg-update-or-status-all {{{ +# >>> +# FUNCTION: .zinit-update-or-status-all <<< # Updates (git pull) or does `git status` for all existing plugins. # This includes also plugins that are not loaded into Zsh (but exist # on disk). Also updates (i.e. redownloads) snippets. # # User-action entry point. --zplg-update-or-status-all() { +.zinit-update-or-status-all() { builtin setopt localoptions nullglob nokshglob noksharrays typesetsilent local st="$1" id_as local repo snip pd user plugin - local -A ZPLG_ICE - ZPLG_ICE=() + local -A ZINIT_ICE + ZINIT_ICE=() local -a snipps - snipps=( ${ZPLGM[SNIPPETS_DIR]}/**/._zplugin(ND) ) + snipps=( ${ZINIT[SNIPPETS_DIR]}/**/(._zinit|._zplugin)(ND) ) [[ "$st" != "status" && "${ICE_OPTS[opt_-q,--quiet]}" != 1 && -n "$snipps" ]] && \ - print "${ZPLGM[col-info]}Note:${ZPLGM[col-rst]} updating also unloaded snippets" + print "${ZINIT[col-info]}Note:${ZINIT[col-rst]} updating also unloaded snippets" - for snip in "${ZPLGM[SNIPPETS_DIR]}"/**/._zplugin/mode(D); do + for snip in "${ZINIT[SNIPPETS_DIR]}"/**/(._zinit|._zplugin)/mode(D); do [[ ! -f "${snip:h}/url" ]] && continue [[ -f "${snip:h}/id-as" ]] && \ id_as="$(<${snip:h}/id-as)" || id_as="" - -zplg-update-or-status-snippet "$st" "${id_as:-$(<${snip:h}/url)}" - ZPLG_ICE=() + .zinit-update-or-status-snippet "$st" "${id_as:-$(<${snip:h}/url)}" + ZINIT_ICE=() done [[ -n "$snipps" ]] && print - ZPLG_ICE=() + ZINIT_ICE=() if [[ "$st" = "status" ]]; then [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && \ - print "${ZPLGM[col-info]}Note:${ZPLGM[col-rst]} status done also for unloaded plugins" + print "${ZINIT[col-info]}Note:${ZINIT[col-rst]} status done also for unloaded plugins" else [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && \ - print "${ZPLGM[col-info]}Note:${ZPLGM[col-rst]} updating also unloaded plugins" + print "${ZINIT[col-info]}Note:${ZINIT[col-rst]} updating also unloaded plugins" fi - for repo in "${ZPLGM[PLUGINS_DIR]}"/*; do + for repo in "${ZINIT[PLUGINS_DIR]}"/*; do pd="${repo:t}" # Two special cases - [[ "$pd" = "custom" || "$pd" = "_local---zplugin" ]] && continue + [[ "$pd" = "custom" || "$pd" = "_local---zinit" ]] && continue - -zplg-any-colorify-as-uspl2 "$pd" + .zinit-any-colorify-as-uspl2 "$pd" # Check if repository has a remote set if [[ -f "$repo/.git/config" ]]; then @@ -1740,11 +1741,11 @@ ZPLGM[EXTENDED_GLOB]="" fi fi - -zplg-any-to-user-plugin "$pd" + .zinit-any-to-user-plugin "$pd" local user="${reply[-2]}" plugin="${reply[-1]}" # Must be a git repository or a binary release - if [[ ! -d "$repo/.git" && ! -f "$repo/._zplugin/is_release" ]]; then + if [[ ! -d "$repo/.git" && ! -f "$repo/._zinit/is_release" ]]; then [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && \ print "\n$REPLY: not a git repository" continue @@ -1755,62 +1756,62 @@ ZPLGM[EXTENDED_GLOB]="" ( builtin cd -q "$repo"; command git status ) else [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print "Updating plugin $REPLY" || print -n . - -zplg-update-or-status "update" "$user" "$plugin" + .zinit-update-or-status "update" "$user" "$plugin" fi done -} # }}} -# FUNCTION: -zplg-show-zstatus {{{ -# Shows Zplugin status, i.e. number of loaded plugins, +} # >>> +# FUNCTION: .zinit-show-zstatus <<< +# Shows Zinit status, i.e. number of loaded plugins, # of available completions, etc. # # User-action entry point. --zplg-show-zstatus() { +.zinit-show-zstatus() { builtin setopt localoptions nullglob extendedglob nokshglob noksharrays - local infoc="${ZPLGM[col-info2]}" + local infoc="${ZINIT[col-info2]}" - print "Zplugin's main directory: ${infoc}${ZPLGM[HOME_DIR]}${ZPLGM[col-rst]}" - print "Zplugin's binary directory: ${infoc}${ZPLGM[BIN_DIR]}${ZPLGM[col-rst]}" - print "Plugin directory: ${infoc}${ZPLGM[PLUGINS_DIR]}${ZPLGM[col-rst]}" - print "Completions directory: ${infoc}${ZPLGM[COMPLETIONS_DIR]}${ZPLGM[col-rst]}" + print "Zinit's main directory: ${infoc}${ZINIT[HOME_DIR]}${ZINIT[col-rst]}" + print "Zinit's binary directory: ${infoc}${ZINIT[BIN_DIR]}${ZINIT[col-rst]}" + print "Plugin directory: ${infoc}${ZINIT[PLUGINS_DIR]}${ZINIT[col-rst]}" + print "Completions directory: ${infoc}${ZINIT[COMPLETIONS_DIR]}${ZINIT[col-rst]}" - # Without _zlocal/zplugin - print "Loaded plugins: ${infoc}$(( ${#ZPLG_REGISTERED_PLUGINS[@]} - 1 ))${ZPLGM[col-rst]}" + # Without _zlocal/zinit + print "Loaded plugins: ${infoc}$(( ${#ZINIT_REGISTERED_PLUGINS[@]} - 1 ))${ZINIT[col-rst]}" # Count light-loaded plugins integer light=0 local s - for s in "${ZPLG_REGISTERED_STATES[@]}"; do + for s in "${ZINIT_REGISTERED_STATES[@]}"; do [[ "$s" = 1 ]] && (( light ++ )) done - # Without _zlocal/zplugin - print "Light loaded: ${infoc}$(( light - 1 ))${ZPLGM[col-rst]}" + # Without _zlocal/zinit + print "Light loaded: ${infoc}$(( light - 1 ))${ZINIT[col-rst]}" - # Downloaded plugins, without _zlocal/zplugin, custom + # Downloaded plugins, without _zlocal/zinit, custom typeset -a plugins - plugins=( "${ZPLGM[PLUGINS_DIR]}"/*(DN) ) - print "Downloaded plugins: ${infoc}$(( ${#plugins} - 1 ))${ZPLGM[col-rst]}" + plugins=( "${ZINIT[PLUGINS_DIR]}"/*(DN) ) + print "Downloaded plugins: ${infoc}$(( ${#plugins} - 1 ))${ZINIT[col-rst]}" - # Number of enabled completions, with _zlocal/zplugin + # Number of enabled completions, with _zlocal/zinit typeset -a completions - completions=( "${ZPLGM[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc(DN) ) - print "Enabled completions: ${infoc}${#completions[@]}${ZPLGM[col-rst]}" + completions=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc(DN) ) + print "Enabled completions: ${infoc}${#completions[@]}${ZINIT[col-rst]}" - # Number of disabled completions, with _zlocal/zplugin - completions=( "${ZPLGM[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN) ) - print "Disabled completions: ${infoc}${#completions[@]}${ZPLGM[col-rst]}" + # Number of disabled completions, with _zlocal/zinit + completions=( "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN) ) + print "Disabled completions: ${infoc}${#completions[@]}${ZINIT[col-rst]}" # Number of completions existing in all plugins - completions=( "${ZPLGM[PLUGINS_DIR]}"/*/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN) ) - print "Completions available overall: ${infoc}${#completions[@]}${ZPLGM[col-rst]}" + completions=( "${ZINIT[PLUGINS_DIR]}"/*/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN) ) + print "Completions available overall: ${infoc}${#completions[@]}${ZINIT[col-rst]}" # Enumerate snippets loaded - print "Snippets loaded: ${infoc}${(j:, :onv)ZPLG_SNIPPETS[@]}${ZPLGM[col-rst]}" + print "Snippets loaded: ${infoc}${(j:, :onv)ZINIT_SNIPPETS[@]}${ZINIT[col-rst]}" # Number of compiled plugins typeset -a matches m integer count=0 - matches=( ${ZPLGM[PLUGINS_DIR]}/*/*.zwc(DN) ) + matches=( ${ZINIT[PLUGINS_DIR]}/*/*.zwc(DN) ) local cur_plugin="" uspl1 for m in "${matches[@]}"; do @@ -1822,13 +1823,13 @@ ZPLGM[EXTENDED_GLOB]="" fi done - print "Compiled plugins: ${infoc}$count${ZPLGM[col-rst]}" -} # }}} -# FUNCTION: -zplg-show-times {{{ + print "Compiled plugins: ${infoc}$count${ZINIT[col-rst]}" +} # >>> +# FUNCTION: .zinit-show-times <<< # Shows loading times of all loaded plugins. # # User-action entry point. --zplg-show-times() { +.zinit-show-times() { setopt localoptions extendedglob nokshglob noksharrays local opt="$1 $2 $3" entry entry2 entry3 user plugin float -F 3 sum=0.0 @@ -1839,31 +1840,31 @@ ZPLGM[EXTENDED_GLOB]="" { print "Plugin loading moments:"; ((1)); } || \ print "Plugin loading times:" - for entry in "${(@on)ZPLGM[(I)TIME_[0-9]##_*]}"; do + for entry in "${(@on)ZINIT[(I)TIME_[0-9]##_*]}"; do entry2="${entry#TIME_[0-9]##_}" entry3="AT_$entry" if [[ "$entry2" = (http|https|ftp|ftps|scp|OMZ|PZT):* ]]; then - REPLY="${ZPLGM[col-pname]}$entry2${ZPLGM[col-rst]}" + REPLY="${ZINIT[col-pname]}$entry2${ZINIT[col-rst]}" - tmp=( "${(z@)ZPLG_SICE[${entry2%/}]}" ) + tmp=( "${(z@)ZINIT_SICE[${entry2%/}]}" ) (( ${#tmp} > 1 && ${#tmp} % 2 == 0 )) && sice=( "${(Q)tmp[@]}" ) || sice=() else user="${entry2%%---*}" plugin="${entry2#*---}" [[ "$user" = \% ]] && plugin="/${plugin//---/\/}" [[ "$user" = "$plugin" && "$user/$plugin" != "$entry2" ]] && user="" - -zplg-any-colorify-as-uspl2 "$user" "$plugin" + .zinit-any-colorify-as-uspl2 "$user" "$plugin" - tmp=( "${(z@)ZPLG_SICE[$user/$plugin]}" ) + tmp=( "${(z@)ZINIT_SICE[$user/$plugin]}" ) (( ${#tmp} > 1 && ${#tmp} % 2 == 0 )) && sice=( "${(Q)tmp[@]}" ) || sice=() fi - local attime=$(( ZPLGM[$entry3] - ZPLGM[START_TIME] )) + local attime=$(( ZINIT[$entry3] - ZINIT[START_TIME] )) if [[ "$opt" = *-[a-z]#s[a-z]#* ]]; then - local time="$ZPLGM[$entry] sec" + local time="$ZINIT[$entry] sec" attime="${(M)attime#*.???} sec" else - local time="${(l:5:: :)$(( ZPLGM[$entry] * 1000 ))%%[,.]*} ms" + local time="${(l:5:: :)$(( ZINIT[$entry] * 1000 ))%%[,.]*} ms" attime="${(l:5:: :)$(( attime * 1000 ))%%[,.]*} ms" fi @@ -1883,13 +1884,13 @@ ZPLGM[EXTENDED_GLOB]="" print "$time" - "$REPLY" fi - (( sum += ZPLGM[$entry] )) + (( sum += ZINIT[$entry] )) done print "Total: $sum sec" } -# }}} -# FUNCTION: -zplg-list-bindkeys {{{ --zplg-list-bindkeys() { +# >>> +# FUNCTION: .zinit-list-bindkeys <<< +.zinit-list-bindkeys() { local uspl2 uspl2col sw first=1 local -a string_widget @@ -1897,19 +1898,19 @@ ZPLGM[EXTENDED_GLOB]="" integer correct=0 [[ -o "KSH_ARRAYS" ]] && correct=1 - for uspl2 in "${(@ko)ZPLGM[(I)BINDKEYS__*]}"; do - [[ -z "${ZPLGM[$uspl2]}" ]] && continue + for uspl2 in "${(@ko)ZINIT[(I)BINDKEYS__*]}"; do + [[ -z "${ZINIT[$uspl2]}" ]] && continue (( !first )) && print first=0 uspl2="${uspl2#BINDKEYS__}" - -zplg-any-colorify-as-uspl2 "$uspl2" + .zinit-any-colorify-as-uspl2 "$uspl2" uspl2col="$REPLY" print "$uspl2col" - string_widget=( "${(z@)ZPLGM[BINDKEYS__$uspl2]}" ) + string_widget=( "${(z@)ZINIT[BINDKEYS__$uspl2]}" ) for sw in "${(Oa)string_widget[@]}"; do [[ -z "$sw" ]] && continue # Remove one level of quoting to split using (z) @@ -1925,11 +1926,11 @@ ZPLGM[EXTENDED_GLOB]="" local sw_arr5="${(Q)sw_arr[5-correct]}" # Optional -R (not with -A, -N) if [[ "$sw_arr3" = "-M" && "$sw_arr5" != "-R" ]]; then - print "bindkey $sw_arr1 $sw_arr2 ${ZPLGM[col-info]}for keymap $sw_arr4${ZPLGM[col-rst]}" + print "bindkey $sw_arr1 $sw_arr2 ${ZINIT[col-info]}for keymap $sw_arr4${ZINIT[col-rst]}" elif [[ "$sw_arr3" = "-M" && "$sw_arr5" = "-R" ]]; then - print "${ZPLGM[col-info]}range${ZPLGM[col-rst]} bindkey $sw_arr1 $sw_arr2 ${ZPLGM[col-info]}mapped to $sw_arr4${ZPLGM[col-rst]}" + print "${ZINIT[col-info]}range${ZINIT[col-rst]} bindkey $sw_arr1 $sw_arr2 ${ZINIT[col-info]}mapped to $sw_arr4${ZINIT[col-rst]}" elif [[ "$sw_arr3" != "-M" && "$sw_arr5" = "-R" ]]; then - print "${ZPLGM[col-info]}range${ZPLGM[col-rst]} bindkey $sw_arr1 $sw_arr2" + print "${ZINIT[col-info]}range${ZINIT[col-rst]} bindkey $sw_arr1 $sw_arr2" elif [[ "$sw_arr3" = "-A" ]]; then print "Override of keymap \`main'" elif [[ "$sw_arr3" = "-N" ]]; then @@ -1940,17 +1941,17 @@ ZPLGM[EXTENDED_GLOB]="" done done } -# }}} +# >>> -# FUNCTION: -zplg-compiled {{{ +# FUNCTION: .zinit-compiled <<< # Displays list of plugins that are compiled. # # User-action entry point. --zplg-compiled() { +.zinit-compiled() { builtin setopt localoptions nullglob typeset -a matches m - matches=( ${ZPLGM[PLUGINS_DIR]}/*/*.zwc(DN) ) + matches=( ${ZINIT[PLUGINS_DIR]}/*/*.zwc(DN) ) if [[ "${#matches[@]}" -eq "0" ]]; then print "No compiled plugins" @@ -1961,65 +1962,65 @@ ZPLGM[EXTENDED_GLOB]="" for m in "${matches[@]}"; do file="${m:t}" uspl1="${${m:h}:t}" - -zplg-any-to-user-plugin "$uspl1" + .zinit-any-to-user-plugin "$uspl1" user="${reply[-2]}" plugin="${reply[-1]}" if [[ "$cur_plugin" != "$uspl1" ]]; then [[ -n "$cur_plugin" ]] && print # newline - -zplg-any-colorify-as-uspl2 "$user" "$plugin" + .zinit-any-colorify-as-uspl2 "$user" "$plugin" print -r -- "$REPLY:" cur_plugin="$uspl1" fi print "$file" done -} # }}} -# FUNCTION: -zplg-compile-uncompile-all {{{ +} # >>> +# FUNCTION: .zinit-compile-uncompile-all <<< # Compiles or uncompiles all existing (on disk) plugins. # # User-action entry point. --zplg-compile-uncompile-all() { +.zinit-compile-uncompile-all() { builtin setopt localoptions nullglob local compile="$1" typeset -a plugins - plugins=( "${ZPLGM[PLUGINS_DIR]}"/*(DN) ) + plugins=( "${ZINIT[PLUGINS_DIR]}"/*(DN) ) local p user plugin for p in "${plugins[@]}"; do - [[ "${p:t}" = "custom" || "${p:t}" = "_local---zplugin" ]] && continue + [[ "${p:t}" = "custom" || "${p:t}" = "_local---zinit" ]] && continue - -zplg-any-to-user-plugin "${p:t}" + .zinit-any-to-user-plugin "${p:t}" user="${reply[-2]}" plugin="${reply[-1]}" - -zplg-any-colorify-as-uspl2 "$user" "$plugin" + .zinit-any-colorify-as-uspl2 "$user" "$plugin" print -r -- "$REPLY:" if [[ "$compile" = "1" ]]; then - -zplg-compile-plugin "$user" "$plugin" + .zinit-compile-plugin "$user" "$plugin" else - -zplg-uncompile-plugin "$user" "$plugin" "1" + .zinit-uncompile-plugin "$user" "$plugin" "1" fi done -} # }}} -# FUNCTION: -zplg-uncompile-plugin {{{ +} # >>> +# FUNCTION: .zinit-uncompile-plugin <<< # Uncompiles given plugin. # # User-action entry point. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user (+ plugin in $2), plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-uncompile-plugin() { +.zinit-uncompile-plugin() { builtin setopt localoptions nullglob - -zplg-any-to-user-plugin "$1" "$2" + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" silent="$3" # There are plugins having ".plugin.zsh" # in ${plugin} directory name, also some # have ".zsh" there - [[ "$user" = "%" ]] && local pdir_path="$plugin" || local pdir_path="${ZPLGM[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" + [[ "$user" = "%" ]] && local pdir_path="$plugin" || local pdir_path="${ZINIT[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" typeset -a matches m matches=( $pdir_path/*.zwc(DN) ) @@ -2027,19 +2028,19 @@ ZPLGM[EXTENDED_GLOB]="" if [[ "$silent" = "1" ]]; then print "not compiled" else - -zplg-any-colorify-as-uspl2 "$user" "$plugin" + .zinit-any-colorify-as-uspl2 "$user" "$plugin" print -r -- "$REPLY not compiled" fi return 1 fi for m in "${matches[@]}"; do - print "Removing ${ZPLGM[col-info]}${m:t}${ZPLGM[col-rst]}" + print "Removing ${ZINIT[col-info]}${m:t}${ZINIT[col-rst]}" command rm -f "$m" done -} # }}} +} # >>> -# FUNCTION: -zplg-show-completions {{{ +# FUNCTION: .zinit-show-completions <<< # Display installed (enabled and disabled), completions. Detect # stray and improper ones. # @@ -2047,18 +2048,18 @@ ZPLGM[EXTENDED_GLOB]="" # installed and enabled. # # User-action entry point. --zplg-show-completions() { +.zinit-show-completions() { builtin setopt localoptions nullglob extendedglob nokshglob noksharrays local count="${1:-3}" typeset -a completions - completions=( "${ZPLGM[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc "${ZPLGM[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) + completions=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) local cpath c o s group # Prepare readlink command for establishing # completion's owner - -zplg-prepare-readlink + .zinit-prepare-readlink local rdlink="$REPLY" float flmax=${#completions} flcur=0 @@ -2076,7 +2077,7 @@ ZPLGM[EXTENDED_GLOB]="" # This will resolve completion's symlink to obtain # information about the repository it comes from, i.e. # about user and plugin, taken from directory name - -zplg-get-completion-owner "$cpath" "$rdlink" + .zinit-get-completion-owner "$cpath" "$rdlink" [[ "$REPLY" = "[unknown]" ]] && unknown=1 || unknown=0 o="$REPLY" @@ -2123,27 +2124,27 @@ ZPLGM[EXTENDED_GLOB]="" for c in "${packs[@]}"; do unpacked=( "${(Q@)${(z@)c}}" ) # TODO: ${(Q)${(z@)c}[@]} ? - -zplg-any-colorify-as-uspl2 "$unpacked[2]" + .zinit-any-colorify-as-uspl2 "$unpacked[2]" print -n "${(r:longest+1:: :)unpacked[1]} $REPLY" - (( unpacked[3] & 0x1 )) && print -n " ${ZPLGM[col-error]}[disabled]${ZPLGM[col-rst]}" - (( unpacked[3] & 0x2 )) && print -n " ${ZPLGM[col-error]}[unknown file, clean with cclear]${ZPLGM[col-rst]}" - (( unpacked[3] & 0x4 )) && print -n " ${ZPLGM[col-error]}[stray, clean with cclear]${ZPLGM[col-rst]}" + (( unpacked[3] & 0x1 )) && print -n " ${ZINIT[col-error]}[disabled]${ZINIT[col-rst]}" + (( unpacked[3] & 0x2 )) && print -n " ${ZINIT[col-error]}[unknown file, clean with cclear]${ZINIT[col-rst]}" + (( unpacked[3] & 0x4 )) && print -n " ${ZINIT[col-error]}[stray, clean with cclear]${ZINIT[col-rst]}" print done -} # }}} -# FUNCTION: -zplg-clear-completions {{{ +} # >>> +# FUNCTION: .zinit-clear-completions <<< # Delete stray and improper completions. # # Completions live even when plugin isn't loaded - if they are # installed and enabled. # # User-action entry point. --zplg-clear-completions() { +.zinit-clear-completions() { builtin setopt localoptions nullglob extendedglob nokshglob noksharrays typeset -a completions - completions=( "${ZPLGM[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc "${ZPLGM[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) + completions=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) # Find longest completion name local cpath c @@ -2154,7 +2155,7 @@ ZPLGM[EXTENDED_GLOB]="" [[ "${#c}" -gt "$longest" ]] && longest="${#c}" done - -zplg-prepare-readlink + .zinit-prepare-readlink local rdlink="$REPLY" integer disabled unknown stray @@ -2166,9 +2167,9 @@ ZPLGM[EXTENDED_GLOB]="" # This will resolve completion's symlink to obtain # information about the repository it comes from, i.e. # about user and plugin, taken from directory name - -zplg-get-completion-owner "$cpath" "$rdlink" + .zinit-get-completion-owner "$cpath" "$rdlink" [[ "$REPLY" = "[unknown]" ]] && unknown=1 || unknown=0 - -zplg-any-colorify-as-uspl2 "$REPLY" + .zinit-any-colorify-as-uspl2 "$REPLY" # If we successfully read a symlink (unknown == 0), test if it isn't broken stray=0 @@ -2178,25 +2179,25 @@ ZPLGM[EXTENDED_GLOB]="" if (( unknown == 1 || stray == 1 )); then print -n "Removing completion: ${(r:longest+1:: :)c} $REPLY" - (( disabled )) && print -n " ${ZPLGM[col-error]}[disabled]${ZPLGM[col-rst]}" - (( unknown )) && print -n " ${ZPLGM[col-error]}[unknown file]${ZPLGM[col-rst]}" - (( stray )) && print -n " ${ZPLGM[col-error]}[stray]${ZPLGM[col-rst]}" + (( disabled )) && print -n " ${ZINIT[col-error]}[disabled]${ZINIT[col-rst]}" + (( unknown )) && print -n " ${ZINIT[col-error]}[unknown file]${ZINIT[col-rst]}" + (( stray )) && print -n " ${ZINIT[col-error]}[stray]${ZINIT[col-rst]}" print command rm -f "$cpath" fi done -} # }}} -# FUNCTION: -zplg-search-completions {{{ -# While -zplg-show-completions() shows what completions are +} # >>> +# FUNCTION: .zinit-search-completions <<< +# While .zinit-show-completions() shows what completions are # installed, this functions searches through all plugin dirs # showing what's available in general (for installation). # # User-action entry point. --zplg-search-completions() { +.zinit-search-completions() { builtin setopt localoptions nullglob extendedglob nokshglob noksharrays typeset -a plugin_paths - plugin_paths=( "${ZPLGM[PLUGINS_DIR]}"/*(DN) ) + plugin_paths=( "${ZINIT[PLUGINS_DIR]}"/*(DN) ) # Find longest plugin name. Things are ran twice here, first pass # is to get longest name of plugin which is having any completions @@ -2211,7 +2212,7 @@ ZPLGM[EXTENDED_GLOB]="" fi done - print "${ZPLGM[col-info]}[+]${ZPLGM[col-rst]} is installed, ${ZPLGM[col-p]}[-]${ZPLGM[col-rst]} uninstalled, ${ZPLGM[col-error]}[+-]${ZPLGM[col-rst]} partially installed" + print "${ZINIT[col-info]}[+]${ZINIT[col-rst]} is installed, ${ZINIT[col-p]}[-]${ZINIT[col-rst]} uninstalled, ${ZINIT[col-error]}[+-]${ZINIT[col-rst]} partially installed" local c for pp in "${plugin_paths[@]}"; do @@ -2224,138 +2225,138 @@ ZPLGM[EXTENDED_GLOB]="" # Detect if the completions are installed integer all_installed="${#completions[@]}" for c in "${completions[@]}"; do - if [[ -e "${ZPLGM[COMPLETIONS_DIR]}/$c" || -e "${ZPLGM[COMPLETIONS_DIR]}/${c#_}" ]]; then + if [[ -e "${ZINIT[COMPLETIONS_DIR]}/$c" || -e "${ZINIT[COMPLETIONS_DIR]}/${c#_}" ]]; then (( all_installed -- )) fi done if [[ "$all_installed" -eq "${#completions[@]}" ]]; then - print -n "${ZPLGM[col-p]}[-]${ZPLGM[col-rst]} " + print -n "${ZINIT[col-p]}[-]${ZINIT[col-rst]} " elif [[ "$all_installed" -eq "0" ]]; then - print -n "${ZPLGM[col-info]}[+]${ZPLGM[col-rst]} " + print -n "${ZINIT[col-info]}[+]${ZINIT[col-rst]} " else - print -n "${ZPLGM[col-error]}[+-]${ZPLGM[col-rst]} " + print -n "${ZINIT[col-error]}[+-]${ZINIT[col-rst]} " fi # Convert directory name to colorified $user/$plugin - -zplg-any-colorify-as-uspl2 "${pp:t}" + .zinit-any-colorify-as-uspl2 "${pp:t}" # Adjust for escape code (nasty, utilizes fact that - # ${ZPLGM[col-rst]} is used twice, so as a $ZPLG_COL) - integer adjust_ec=$(( ${#ZPLGM[col-rst]} * 2 + ${#ZPLGM[col-uname]} + ${#ZPLGM[col-pname]} )) + # ${ZINIT[col-rst]} is used twice, so as a $ZINIT_COL) + integer adjust_ec=$(( ${#ZINIT[col-rst]} * 2 + ${#ZINIT[col-uname]} + ${#ZINIT[col-pname]} )) print "${(r:longest+adjust_ec:: :)REPLY} ${(j:, :)completions}" fi done -} # }}} -# FUNCTION: -zplg-cenable {{{ +} # >>> +# FUNCTION: .zinit-cenable <<< # Disables given installed completion. # # User-action entry point. # # $1 - e.g. "_mkdir" or "mkdir" --zplg-cenable() { +.zinit-cenable() { local c="$1" c="${c#_}" - local cfile="${ZPLGM[COMPLETIONS_DIR]}/_${c}" + local cfile="${ZINIT[COMPLETIONS_DIR]}/_${c}" local bkpfile="${cfile:h}/$c" if [[ ! -e "$cfile" && ! -e "$bkpfile" ]]; then - print "${ZPLGM[col-error]}No such completion \`$c'${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}No such completion \`$c'${ZINIT[col-rst]}" return 1 fi # Check if there is no backup file # This is treated as if the completion is already enabled if [[ ! -e "$bkpfile" ]]; then - print "Completion ${ZPLGM[col-info]}$c${ZPLGM[col-rst]} already enabled" + print "Completion ${ZINIT[col-info]}$c${ZINIT[col-rst]} already enabled" - -zplg-check-comp-consistency "$cfile" "$bkpfile" 0 + .zinit-check-comp-consistency "$cfile" "$bkpfile" 0 return 1 fi # Disabled, but completion file already exists? if [[ -e "$cfile" ]]; then - print "${ZPLGM[col-error]}Warning: completion's file \`${cfile:t}' exists, will overwrite${ZPLGM[col-rst]}" - print "${ZPLGM[col-error]}Completion is actually enabled and will re-enable it again${ZPLGM[col-rst]}" - -zplg-check-comp-consistency "$cfile" "$bkpfile" 1 + print "${ZINIT[col-error]}Warning: completion's file \`${cfile:t}' exists, will overwrite${ZINIT[col-rst]}" + print "${ZINIT[col-error]}Completion is actually enabled and will re-enable it again${ZINIT[col-rst]}" + .zinit-check-comp-consistency "$cfile" "$bkpfile" 1 command rm -f "$cfile" else - -zplg-check-comp-consistency "$cfile" "$bkpfile" 0 + .zinit-check-comp-consistency "$cfile" "$bkpfile" 0 fi # Enable command mv "$bkpfile" "$cfile" # move completion's backup file created when disabling # Prepare readlink command for establishing completion's owner - -zplg-prepare-readlink + .zinit-prepare-readlink # Get completion's owning plugin - -zplg-get-completion-owner-uspl2col "$cfile" "$REPLY" + .zinit-get-completion-owner-uspl2col "$cfile" "$REPLY" - print "Enabled ${ZPLGM[col-info]}$c${ZPLGM[col-rst]} completion belonging to $REPLY" + print "Enabled ${ZINIT[col-info]}$c${ZINIT[col-rst]} completion belonging to $REPLY" return 0 -} # }}} -# FUNCTION: -zplg-cdisable {{{ +} # >>> +# FUNCTION: .zinit-cdisable <<< # Enables given installed completion. # # User-action entry point. # # $1 - e.g. "_mkdir" or "mkdir" --zplg-cdisable() { +.zinit-cdisable() { local c="$1" c="${c#_}" - local cfile="${ZPLGM[COMPLETIONS_DIR]}/_${c}" + local cfile="${ZINIT[COMPLETIONS_DIR]}/_${c}" local bkpfile="${cfile:h}/$c" if [[ ! -e "$cfile" && ! -e "$bkpfile" ]]; then - print "${ZPLGM[col-error]}No such completion \`$c'${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}No such completion \`$c'${ZINIT[col-rst]}" return 1 fi # Check if it's already disabled # Not existing "$cfile" says that if [[ ! -e "$cfile" ]]; then - print "Completion ${ZPLGM[col-info]}$c${ZPLGM[col-rst]} already disabled" + print "Completion ${ZINIT[col-info]}$c${ZINIT[col-rst]} already disabled" - -zplg-check-comp-consistency "$cfile" "$bkpfile" 0 + .zinit-check-comp-consistency "$cfile" "$bkpfile" 0 return 1 fi # No disable, but bkpfile exists? if [[ -e "$bkpfile" ]]; then - print "${ZPLGM[col-error]}Warning: completion's backup file \`${bkpfile:t}' already exists, will overwrite${ZPLGM[col-rst]}" - -zplg-check-comp-consistency "$cfile" "$bkpfile" 1 + print "${ZINIT[col-error]}Warning: completion's backup file \`${bkpfile:t}' already exists, will overwrite${ZINIT[col-rst]}" + .zinit-check-comp-consistency "$cfile" "$bkpfile" 1 command rm -f "$bkpfile" else - -zplg-check-comp-consistency "$cfile" "$bkpfile" 0 + .zinit-check-comp-consistency "$cfile" "$bkpfile" 0 fi # Disable command mv "$cfile" "$bkpfile" # Prepare readlink command for establishing completion's owner - -zplg-prepare-readlink + .zinit-prepare-readlink # Get completion's owning plugin - -zplg-get-completion-owner-uspl2col "$bkpfile" "$REPLY" + .zinit-get-completion-owner-uspl2col "$bkpfile" "$REPLY" - print "Disabled ${ZPLGM[col-info]}$c${ZPLGM[col-rst]} completion belonging to $REPLY" + print "Disabled ${ZINIT[col-info]}$c${ZINIT[col-rst]} completion belonging to $REPLY" return 0 -} # }}} +} # >>> -# FUNCTION: -zplg-cd {{{ -# Jumps to plugin's directory (in Zplugin's home directory). +# FUNCTION: .zinit-cd <<< +# Jumps to plugin's directory (in Zinit's home directory). # # User-action entry point. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-cd() { +.zinit-cd() { setopt localoptions extendedglob nokshglob noksharrays - -zplg-get-path "$1" "$2" && { + .zinit-get-path "$1" "$2" && { if [[ -e "$REPLY" ]]; then builtin cd "$REPLY" else @@ -2367,31 +2368,31 @@ ZPLGM[EXTENDED_GLOB]="" print -r -- "No such plugin or snippet" return 1 } -} # }}} -# FUNCTION: -zplg-run-delete-hooks {{{ --zplg-run-delete-hooks() { - if [[ -n ${ZPLG_ICE[atdelete]} ]]; then - -zplg-countdown "atdelete" && ( (( ${+ZPLG_ICE[nocd]} == 0 )) && \ - { builtin cd -q "$5" && eval "${ZPLG_ICE[atdelete]}"; ((1)); } || \ - eval "${ZPLG_ICE[atdelete]}" ) +} # >>> +# FUNCTION: .zinit-run-delete-hooks <<< +.zinit-run-delete-hooks() { + if [[ -n ${ZINIT_ICE[atdelete]} ]]; then + .zinit-countdown "atdelete" && ( (( ${+ZINIT_ICE[nocd]} == 0 )) && \ + { builtin cd -q "$5" && eval "${ZINIT_ICE[atdelete]}"; ((1)); } || \ + eval "${ZINIT_ICE[atdelete]}" ) fi local -a arr local key - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atdelete <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atdelete <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "$1" "$2" $3 "$4" "$5" atdelete done } -# }}} -# FUNCTION: -zplg-delete {{{ -# Deletes plugin's or snippet's directory (in Zplugin's home directory). +# >>> +# FUNCTION: .zinit-delete <<< +# Deletes plugin's or snippet's directory (in Zinit's home directory). # # User-action entry point. # # $1 - snippet URL or plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-delete() { +.zinit-delete() { setopt localoptions extendedglob nokshglob noksharrays warncreateglobal # Parse options @@ -2404,28 +2405,28 @@ ZPLGM[EXTENDED_GLOB]="" # --all given? if (( ICE_OPTS[opt_--all] )); then - -zplg-confirm "Prune all plugins in \`${ZPLGM[PLUGINS_DIR]}'"\ -"and snippets in \`${ZPLGM[SNIPPETS_DIR]}'?" \ -"command rm -rf ${${ZPLGM[PLUGINS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/_local---zplugin(ND) "\ -"${${ZPLGM[SNIPPETS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/plugins(ND)" + .zinit-confirm "Prune all plugins in \`${ZINIT[PLUGINS_DIR]}'"\ +"and snippets in \`${ZINIT[SNIPPETS_DIR]}'?" \ +"command rm -rf ${${ZINIT[PLUGINS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/_local---zinit(ND) "\ +"${${ZINIT[SNIPPETS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/plugins(ND)" return $? fi # --clean given? if (( ICE_OPTS[opt_--clean] )); then - -zplg-confirm "Prune ${ZPLGM[col-info]}CURRENTLY NOT LOADED${ZPLGM[col-rst]}"\ -" plugins in ${ZPLGM[PLUGINS_DIR]}"\ -" and snippets in ${ZPLGM[SNIPPETS_DIR]}?" \ -"command rm -rf ${${ZPLGM[PLUGINS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/(${(j:|:)${ZPLG_REGISTERED_PLUGINS[@]//\//---}})(ND) "\ -"${${ZPLGM[SNIPPETS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/(plugins|OMZ::lib|${(j:|:)${(@)${(@)${${ZPLG_SNIPPETS[@]% <*>}[@]:h}//\//--}}})(ND)" + .zinit-confirm "Prune ${ZINIT[col-info]}CURRENTLY NOT LOADED${ZINIT[col-rst]}"\ +" plugins in ${ZINIT[PLUGINS_DIR]}"\ +" and snippets in ${ZINIT[SNIPPETS_DIR]}?" \ +"command rm -rf ${${ZINIT[PLUGINS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/(${(j:|:)${ZINIT_REGISTERED_PLUGINS[@]//\//---}})(ND) "\ +"${${ZINIT[SNIPPETS_DIR]##[[:space:]]##}:-/tmp/abcEFG312}/*~*/(plugins|OMZ::lib|${(j:|:)${(@)${(@)${${ZINIT_SNIPPETS[@]% <*>}[@]:h}//\//--}}})(ND)" return $? fi - local -A ZPLG_ICE + local -A ZINIT_ICE local local_dir filename is_snippet - -zplg-compute-ice "$the_id" "pack" \ - ZPLG_ICE local_dir filename is_snippet || return 1 + .zinit-compute-ice "$the_id" "pack" \ + ZINIT_ICE local_dir filename is_snippet || return 1 if [[ "$local_dir" != /* ]] then @@ -2433,23 +2434,23 @@ ZPLGM[EXTENDED_GLOB]="" return 1 fi - ZPLG_ICE[teleid]="${ZPLG_ICE[teleid]:-${ZPLG_ICE[id-as]}}" + ZINIT_ICE[teleid]="${ZINIT_ICE[teleid]:-${ZINIT_ICE[id-as]}}" local -a files files=( "$local_dir"/*.(zsh|sh|bash|ksh)(DN:t) "$local_dir"/*(*DN:t) "$local_dir"/*(@DN:t) "$local_dir"/*(.DN:t) - "$local_dir"/*~*/.(_zplugin|svn|git)(/DN:t) "$local_dir"/*(=DN:t) + "$local_dir"/*~*/.(_zinit|svn|git)(/DN:t) "$local_dir"/*(=DN:t) "$local_dir"/*(pDN:t) "$local_dir"/*(%DN:t) ) (( !${#files} )) && files=( "no files?" ) files=( ${(@)files[1,4]} ${files[4]+more…} ) if (( is_snippet )); then - if [[ "${+ZPLG_ICE[svn]}" = "1" ]] { + if [[ "${+ZINIT_ICE[svn]}" = "1" ]] { if [[ -e "$local_dir" ]] then - -zplg-confirm "Delete $local_dir? (it holds: ${(j:, :)${(@u)files}})" \ - "-zplg-run-delete-hooks snippet \"${ZPLG_ICE[teleid]}\" \"\" \"$the_id\" \ + .zinit-confirm "Delete $local_dir? (it holds: ${(j:, :)${(@u)files}})" \ + ".zinit-run-delete-hooks snippet \"${ZINIT_ICE[teleid]}\" \"\" \"$the_id\" \ \"$local_dir\"; \ command rm -rf ${(q)${${local_dir:#/}:-/tmp/abcYZX321}}" else @@ -2458,8 +2459,8 @@ ZPLGM[EXTENDED_GLOB]="" fi } else { if [[ -e "$local_dir" ]]; then - -zplg-confirm "Delete $local_dir? (it holds: ${(j:, :)${(@u)files}})" \ - "-zplg-run-delete-hooks snippet \"${ZPLG_ICE[teleid]}\" \"\" \"$the_id\" \ + .zinit-confirm "Delete $local_dir? (it holds: ${(j:, :)${(@u)files}})" \ + ".zinit-run-delete-hooks snippet \"${ZINIT_ICE[teleid]}\" \"\" \"$the_id\" \ \"$local_dir\"; command rm -rf \ ${(q)${${local_dir:#/}:-/tmp/abcYZX321}}" else @@ -2468,10 +2469,10 @@ ZPLGM[EXTENDED_GLOB]="" fi } else - -zplg-any-to-user-plugin "${ZPLG_ICE[teleid]}" + .zinit-any-to-user-plugin "${ZINIT_ICE[teleid]}" if [[ -e "$local_dir" ]]; then - -zplg-confirm "Delete $local_dir? (it holds: ${(j:, :)${(@u)files}})" \ - "-zplg-run-delete-hooks plugin \"${reply[-2]}\" \"${reply[-1]}\" \"$the_id\" \ + .zinit-confirm "Delete $local_dir? (it holds: ${(j:, :)${(@u)files}})" \ + ".zinit-run-delete-hooks plugin \"${reply[-2]}\" \"${reply[-1]}\" \"$the_id\" \ \"$local_dir\"; \ command rm -rf ${(q)${${local_dir:#/}:-/tmp/abcYZX321}}" else @@ -2481,14 +2482,14 @@ ZPLGM[EXTENDED_GLOB]="" fi return 0 -} # }}} -# FUNCTION: -zplg-confirm {{{ +} # >>> +# FUNCTION: .zinit-confirm <<< # Prints given question, waits for "y" key, evals # given expression if "y" obtained # # $1 - question # $2 - expression --zplg-confirm() { +.zinit-confirm() { if (( ICE_OPTS[opt_-y,--yes] )); then integer retval eval "$2"; retval=$? @@ -2502,32 +2503,32 @@ ZPLGM[EXTENDED_GLOB]="" fi return 0 } -# }}} -# FUNCTION: -zplg-changes {{{ +# >>> +# FUNCTION: .zinit-changes <<< # Shows `git log` of given plugin. # # User-action entry point. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-changes() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-changes() { + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" - -zplg-exists-physically-message "$user" "$plugin" || return 1 + .zinit-exists-physically-message "$user" "$plugin" || return 1 ( - builtin cd -q "${ZPLGM[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" && \ + builtin cd -q "${ZINIT[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" && \ command git log -p --graph --decorate --date=relative -C -M ) -} # }}} -# FUNCTION: -zplg-recently {{{ +} # >>> +# FUNCTION: .zinit-recently <<< # Shows plugins that obtained commits in specified past time. # # User-action entry point. # # $1 - time spec, e.g. "1 week" --zplg-recently() { +.zinit-recently() { builtin setopt localoptions nullglob extendedglob nokshglob noksharrays local IFS="." @@ -2537,41 +2538,41 @@ ZPLGM[EXTENDED_GLOB]="" [[ -z "$timespec" ]] && timespec="1.week" typeset -a plugins - plugins=( "${ZPLGM[PLUGINS_DIR]}"/*(DN) ) + plugins=( "${ZINIT[PLUGINS_DIR]}"/*(DN) ) local p uspl1 for p in "${plugins[@]}"; do uspl1="${p:t}" - [[ "$uspl1" = "custom" || "$uspl1" = "_local---zplugin" ]] && continue + [[ "$uspl1" = "custom" || "$uspl1" = "_local---zinit" ]] && continue pushd "$p" >/dev/null if [[ -d ".git" ]]; then gitout=`command git log --all --max-count=1 --since=$timespec 2>/dev/null` if [[ -n "$gitout" ]]; then - -zplg-any-colorify-as-uspl2 "$uspl1" + .zinit-any-colorify-as-uspl2 "$uspl1" print -r -- "$REPLY" fi fi popd >/dev/null done -} # }}} -# FUNCTION: -zplg-create {{{ +} # >>> +# FUNCTION: .zinit-create <<< # Creates a plugin, also on Github (if not "_local/name" plugin). # # User-action entry point. # # $1 - (optional) plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - (optional) plugin (only when $1 - i.e. user - given) --zplg-create() { +.zinit-create() { emulate -LR zsh setopt localoptions extendedglob warncreateglobal typesetsilent \ noshortloops rcquotes - -zplg-any-to-user-plugin "$1" "$2" + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" if (( ${+commands[curl]} == 0 || ${+commands[git]} == 0 )); then - print "${ZPLGM[col-error]}curl and git are needed${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}curl and git are needed${ZINIT[col-rst]}" return 1 fi @@ -2593,38 +2594,38 @@ ZPLGM[EXTENDED_GLOB]="" vared -cp 'Plugin name: ' plugin if [[ "$plugin" = "_unknown" ]]; then - print "${ZPLGM[col-error]}No plugin name entered${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}No plugin name entered${ZINIT[col-rst]}" return 1 fi plugin="${plugin//[^a-zA-Z0-9_]##/-}" - -zplg-any-colorify-as-uspl2 "${${${(M)isorg:#(y|yes)}:+$org}:-$user}" "$plugin" + .zinit-any-colorify-as-uspl2 "${${${(M)isorg:#(y|yes)}:+$org}:-$user}" "$plugin" local uspl2col="$REPLY" print "Plugin is $uspl2col" - if -zplg-exists-physically "${${${(M)isorg:#(y|yes)}:+$org}:-$user}" "$plugin"; then - print "${ZPLGM[col-error]}Repository${ZPLGM[col-rst]} $uspl2col ${ZPLGM[col-error]}already exists locally${ZPLGM[col-rst]}" + if .zinit-exists-physically "${${${(M)isorg:#(y|yes)}:+$org}:-$user}" "$plugin"; then + print "${ZINIT[col-error]}Repository${ZINIT[col-rst]} $uspl2col ${ZINIT[col-error]}already exists locally${ZINIT[col-rst]}" return 1 fi - builtin cd -q "${ZPLGM[PLUGINS_DIR]}" + builtin cd -q "${ZINIT[PLUGINS_DIR]}" if [[ "$user" != "_local" && -n "$user" ]]; then - print "${ZPLGM[col-info]}Creating Github repository${ZPLGM[col-rst]}" + print "${ZINIT[col-info]}Creating Github repository${ZINIT[col-rst]}" if [[ $isorg = (y|yes) ]]; then curl --silent -u "$user" https://api.github.com/orgs/$org/repos -d '{"name":"'"$plugin"'"}' >/dev/null else curl --silent -u "$user" https://api.github.com/user/repos -d '{"name":"'"$plugin"'"}' >/dev/null fi command git clone "https://github.com/${${${(M)isorg:#(y|yes)}:+$org}:-$user}/${plugin}.git" "${${${(M)isorg:#(y|yes)}:+$org}:-$user}---${plugin//\//---}" || { - print "${ZPLGM[col-error]}Creation of remote repository $uspl2col ${ZPLGM[col-error]}failed${ZPLGM[col-rst]}" - print "${ZPLGM[col-error]}Bad credentials?${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}Creation of remote repository $uspl2col ${ZINIT[col-error]}failed${ZINIT[col-rst]}" + print "${ZINIT[col-error]}Bad credentials?${ZINIT[col-rst]}" return 1 } builtin cd -q "${${${(M)isorg:#(y|yes)}:+$org}:-$user}---${plugin//\//---}" command git config credential.https://github.com.username "${user}" else - print "${ZPLGM[col-info]}Creating local git repository${${user:+.}:-, ${ZPLGM[col-pname]}free-style, without the \"_local/\" part${ZPLGM[col-info]}.}${ZPLGM[col-rst]}" + print "${ZINIT[col-info]}Creating local git repository${${user:+.}:-, ${ZINIT[col-pname]}free-style, without the \"_local/\" part${ZINIT[col-info]}.}${ZINIT[col-rst]}" command mkdir "${user:+${user}---}${plugin//\//---}" builtin cd -q "${user:+${user}---}${plugin//\//---}" command git init || { @@ -2662,9 +2663,9 @@ autoload -Uz example-script EOF print -r -- "# $plugin" >! "README.md" - command cp -vf "${ZPLGM[BIN_DIR]}/LICENSE" LICENSE - command cp -vf "${ZPLGM[BIN_DIR]}/doc/Zsh.gitignore" .gitignore - command cp -vf "${ZPLGM[BIN_DIR]}/doc/example-script" . + command cp -vf "${ZINIT[BIN_DIR]}/LICENSE" LICENSE + command cp -vf "${ZINIT[BIN_DIR]}/doc/Zsh.gitignore" .gitignore + command cp -vf "${ZINIT[BIN_DIR]}/doc/example-script" . command sed -i -e "s/MY_PLUGIN_DIR/${${(U)plugin:t}//-/_}_DIR/g" example-script command sed -i -e "s/USER_NAME/$user_name/g" example-script @@ -2679,8 +2680,8 @@ EOF print "Created local $uspl2col plugin." print "You're in plugin's repository folder, the files aren't added to git." fi -} # }}} -# FUNCTION: -zplg-glance {{{ +} # >>> +# FUNCTION: .zinit-glance <<< # Shows colorized source code of plugin. Is able to use pygmentize, # highlight, GNU source-highlight. # @@ -2688,14 +2689,14 @@ EOF # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-glance() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-glance() { + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" - -zplg-exists-physically-message "$user" "$plugin" || return 1 + .zinit-exists-physically-message "$user" "$plugin" || return 1 - -zplg-first "$1" "$2" || { - print "${ZPLGM[col-error]}No source file found, cannot glance${ZPLGM[col-rst]}" + .zinit-first "$1" "$2" || { + print "${ZINIT[col-error]}No source file found, cannot glance${ZINIT[col-rst]}" return 1 } @@ -2706,30 +2707,30 @@ EOF { if (( ${+commands[pygmentize]} )); then - print "Glancing with ${ZPLGM[col-info]}pygmentize${ZPLGM[col-rst]}" + print "Glancing with ${ZINIT[col-info]}pygmentize${ZINIT[col-rst]}" pygmentize -l bash -g "$fname" elif (( ${+commands[highlight]} )); then - print "Glancing with ${ZPLGM[col-info]}highlight${ZPLGM[col-rst]}" + print "Glancing with ${ZINIT[col-info]}highlight${ZINIT[col-rst]}" if (( has_256_colors )); then highlight -q --force -S sh -O xterm256 "$fname" else highlight -q --force -S sh -O ansi "$fname" fi elif (( ${+commands[source-highlight]} )); then - print "Glancing with ${ZPLGM[col-info]}source-highlight${ZPLGM[col-rst]}" + print "Glancing with ${ZINIT[col-info]}source-highlight${ZINIT[col-rst]}" source-highlight -fesc --failsafe -s zsh -o STDOUT -i "$fname" else cat "$fname" fi } | { if [[ -t 1 ]]; then - -zplg-pager + .zinit-pager else cat fi } -} # }}} -# FUNCTION: -zplg-edit {{{ +} # >>> +# FUNCTION: .zinit-edit <<< # Runs $EDITOR on source of given plugin. If the variable is not # set then defaults to `vim'. # @@ -2737,14 +2738,14 @@ EOF # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-edit() { - local -A ZPLG_ICE +.zinit-edit() { + local -A ZINIT_ICE local local_dir filename is_snippet the_id="$1${${1:#(%|/)*}:+${2:+/}}$2" - -zplg-compute-ice "$the_id" "pack" \ - ZPLG_ICE local_dir filename is_snippet || return 1 + .zinit-compute-ice "$the_id" "pack" \ + ZINIT_ICE local_dir filename is_snippet || return 1 - ZPLG_ICE[teleid]="${ZPLG_ICE[teleid]:-${ZPLG_ICE[id-as]}}" + ZINIT_ICE[teleid]="${ZINIT_ICE[teleid]:-${ZINIT_ICE[id-as]}}" if (( is_snippet )); then if [[ ! -e "$local_dir" ]]; then @@ -2760,8 +2761,8 @@ EOF "${EDITOR:-vim}" "$local_dir" return 0 -} # }}} -# FUNCTION: -zplg-stress {{{ +} # >>> +# FUNCTION: .zinit-stress <<< # Compiles plugin with various options on and off to see # how well the code is written. The options are: # @@ -2772,14 +2773,14 @@ EOF # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-stress() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-stress() { + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" - -zplg-exists-physically-message "$user" "$plugin" || return 1 + .zinit-exists-physically-message "$user" "$plugin" || return 1 - -zplg-first "$1" "$2" || { - print "${ZPLGM[col-error]}No source file found, cannot stress${ZPLGM[col-rst]}" + .zinit-first "$1" "$2" || { + print "${ZINIT[col-error]}No source file found, cannot stress${ZINIT[col-rst]}" return 1 } @@ -2788,8 +2789,8 @@ EOF integer compiled=1 [[ -e "${fname}.zwc" ]] && command rm -f "${fname}.zwc" || compiled=0 - local -a ZPLG_STRESS_TEST_OPTIONS - ZPLG_STRESS_TEST_OPTIONS=( + local -a ZINIT_STRESS_TEST_OPTIONS + ZINIT_STRESS_TEST_OPTIONS=( "NO_SHORT_LOOPS" "IGNORE_BRACES" "IGNORE_CLOSE_BRACES" "SH_GLOB" "CSH_JUNKIE_QUOTES" "NO_MULTI_FUNC_DEF" ) @@ -2797,13 +2798,13 @@ EOF ( emulate -LR ksh builtin unsetopt shglob kshglob - for i in "${ZPLG_STRESS_TEST_OPTIONS[@]}"; do + for i in "${ZINIT_STRESS_TEST_OPTIONS[@]}"; do builtin setopt "$i" print -n "Stress-testing ${fname:t} for option $i " zcompile -R "$fname" 2>/dev/null && { - print "[${ZPLGM[col-success]}Success${ZPLGM[col-rst]}]" + print "[${ZINIT[col-success]}Success${ZINIT[col-rst]}]" } || { - print "[${ZPLGM[col-failure]}Fail${ZPLGM[col-rst]}]" + print "[${ZINIT[col-failure]}Fail${ZINIT[col-rst]}]" } builtin unsetopt "$i" done @@ -2811,55 +2812,55 @@ EOF command rm -f "${fname}.zwc" (( compiled )) && zcompile "$fname" -} # }}} -# FUNCTION: -zplg-list-compdef-replay {{{ +} # >>> +# FUNCTION: .zinit-list-compdef-replay <<< # Shows recorded compdefs (called by plugins loaded earlier). # Plugins often call `compdef' hoping for `compinit' being -# already ran. Zplugin solves this by recording compdefs. +# already ran. Zinit solves this by recording compdefs. # # User-action entry point. --zplg-list-compdef-replay() { +.zinit-list-compdef-replay() { print "Recorded compdefs:" local cdf - for cdf in "${ZPLG_COMPDEF_REPLAY[@]}"; do + for cdf in "${ZINIT_COMPDEF_REPLAY[@]}"; do print "compdef ${(Q)cdf}" done -} # }}} -# FUNCTION: -zplg-ls {{{ --zplg-ls() { +} # >>> +# FUNCTION: .zinit-ls <<< +.zinit-ls() { (( ${+commands[tree]} )) || { - print "${ZPLGM[col-error]}No \`tree' program, it is required by the subcommand \`ls\'${ZPLGM[col-rst]}" + print "${ZINIT[col-error]}No \`tree' program, it is required by the subcommand \`ls\'${ZINIT[col-rst]}" print "Download from: http://mama.indstate.edu/users/ice/tree/" print "It is also available probably in all distributions and Homebrew, as package \`tree'" } ( setopt localoptions extendedglob nokshglob noksharrays - builtin cd -q "${ZPLGM[SNIPPETS_DIR]}" + builtin cd -q "${ZINIT[SNIPPETS_DIR]}" local -a list list=( "${(f@)"$(LANG=en_US.utf-8 tree -L 3 --charset utf-8)"}" ) # Oh-My-Zsh single file - list=( "${list[@]//(#b)(https--github.com--robbyrussell--oh-my-zsh--raw--master(--)(#c0,1)(*))/$ZPLGM[col-info]Oh-My-Zsh$ZPLGM[col-error]${match[2]/--//}$ZPLGM[col-pname]${match[3]//--/$ZPLGM[col-error]/$ZPLGM[col-pname]} $ZPLGM[col-info](single-file)$ZPLGM[col-rst] ${match[1]}}" ) + list=( "${list[@]//(#b)(https--github.com--robbyrussell--oh-my-zsh--raw--master(--)(#c0,1)(*))/$ZINIT[col-info]Oh-My-Zsh$ZINIT[col-error]${match[2]/--//}$ZINIT[col-pname]${match[3]//--/$ZINIT[col-error]/$ZINIT[col-pname]} $ZINIT[col-info](single-file)$ZINIT[col-rst] ${match[1]}}" ) # Oh-My-Zsh SVN - list=( "${list[@]//(#b)(https--github.com--robbyrussell--oh-my-zsh--trunk(--)(#c0,1)(*))/$ZPLGM[col-info]Oh-My-Zsh$ZPLGM[col-error]${match[2]/--//}$ZPLGM[col-pname]${match[3]//--/$ZPLGM[col-error]/$ZPLGM[col-pname]} $ZPLGM[col-info](SVN)$ZPLGM[col-rst] ${match[1]}}" ) + list=( "${list[@]//(#b)(https--github.com--robbyrussell--oh-my-zsh--trunk(--)(#c0,1)(*))/$ZINIT[col-info]Oh-My-Zsh$ZINIT[col-error]${match[2]/--//}$ZINIT[col-pname]${match[3]//--/$ZINIT[col-error]/$ZINIT[col-pname]} $ZINIT[col-info](SVN)$ZINIT[col-rst] ${match[1]}}" ) # Prezto single file - list=( "${list[@]//(#b)(https--github.com--sorin-ionescu--prezto--raw--master(--)(#c0,1)(*))/$ZPLGM[col-info]Prezto$ZPLGM[col-error]${match[2]/--//}$ZPLGM[col-pname]${match[3]//--/$ZPLGM[col-error]/$ZPLGM[col-pname]} $ZPLGM[col-info](single-file)$ZPLGM[col-rst] ${match[1]}}" ) + list=( "${list[@]//(#b)(https--github.com--sorin-ionescu--prezto--raw--master(--)(#c0,1)(*))/$ZINIT[col-info]Prezto$ZINIT[col-error]${match[2]/--//}$ZINIT[col-pname]${match[3]//--/$ZINIT[col-error]/$ZINIT[col-pname]} $ZINIT[col-info](single-file)$ZINIT[col-rst] ${match[1]}}" ) # Prezto SVN - list=( "${list[@]//(#b)(https--github.com--sorin-ionescu--prezto--trunk(--)(#c0,1)(*))/$ZPLGM[col-info]Prezto$ZPLGM[col-error]${match[2]/--//}$ZPLGM[col-pname]${match[3]//--/$ZPLGM[col-error]/$ZPLGM[col-pname]} $ZPLGM[col-info](SVN)$ZPLGM[col-rst] ${match[1]}}" ) + list=( "${list[@]//(#b)(https--github.com--sorin-ionescu--prezto--trunk(--)(#c0,1)(*))/$ZINIT[col-info]Prezto$ZINIT[col-error]${match[2]/--//}$ZINIT[col-pname]${match[3]//--/$ZINIT[col-error]/$ZINIT[col-pname]} $ZINIT[col-info](SVN)$ZINIT[col-rst] ${match[1]}}" ) # First-level names - list=( "${list[@]//(#b)(#s)(β”‚Β Β  └──| └──| β”œβ”€β”€|β”‚Β Β  β”œβ”€β”€) (*)/${match[1]} $ZPLGM[col-error]${match[2]}$ZPLGM[col-rst]}" ) + list=( "${list[@]//(#b)(#s)(β”‚Β Β  └──| └──| β”œβ”€β”€|β”‚Β Β  β”œβ”€β”€) (*)/${match[1]} $ZINIT[col-error]${match[2]}$ZINIT[col-rst]}" ) - list[-1]+=", located at ZPLGM[SNIPPETS_DIR], i.e. ${ZPLGM[SNIPPETS_DIR]}" + list[-1]+=", located at ZINIT[SNIPPETS_DIR], i.e. ${ZINIT[SNIPPETS_DIR]}" print -rl -- "${list[@]}" ) } -# }}} -# FUNCTION: -zplg-get-path {{{ +# >>> +# FUNCTION: .zinit-get-path <<< # Returns path of given ID-string, which may be a plugin-spec # (like "user/plugin" or "user" "plugin"), an absolute path # ("%" "/home/..." and also "%SNIPPETS/..." etc.), or a plugin # nickname (i.e. id-as'' ice-mod), or a snippet nickname. --zplg-get-path() { +.zinit-get-path() { emulate -LR zsh setopt extendedglob warncreateglobal typesetsilent noshortloops @@ -2870,7 +2871,7 @@ EOF return 0 fi - -zplg-two-paths "$the_id" + .zinit-two-paths "$the_id" local s_path="${reply[-4]}" s_svn="${reply[-3]}" _path="${reply[-2]}" _filename="${reply[-1]}" reply=() @@ -2879,7 +2880,7 @@ EOF if [[ -d "$s_path" || -d "$_path" ]]; then local -A sice local -a tmp - tmp=( "${(z@)ZPLG_SICE[$the_id]}" ) + tmp=( "${(z@)ZINIT_SICE[$the_id]}" ) (( ${#tmp} > 1 && ${#tmp} % 2 == 0 )) && sice=( "${(Q)tmp[@]}" ) [[ "${+sice[svn]}" = "1" || -n "$s_svn" ]] && { @@ -2889,24 +2890,24 @@ EOF [[ -e "$_path" ]] && REPLY="$_path" } else - -zplg-any-to-user-plugin "$1" "$2" + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" reply=() - -zplg-exists-physically "$user" "$plugin" || return 1 + .zinit-exists-physically "$user" "$plugin" || return 1 - -zplg-shands-exp "$1" "$2" && { + .zinit-shands-exp "$1" "$2" && { : } || { - REPLY="${ZPLGM[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" + REPLY="${ZINIT[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" } fi return 0 } -# }}} -# FUNCTION: -zplg-recall {{{ --zplg-recall() { +# >>> +# FUNCTION: .zinit-recall <<< +.zinit-recall() { local -A ice local el val cand1 cand2 local_dir filename is_snippet @@ -2922,7 +2923,7 @@ EOF subscribe param # Include all additional ices – after # stripping them from the possible: '' - ${(@us.|.)${ZPLG_EXTS[ice-mods]//\'\'/}} + ${(@us.|.)${ZINIT_EXTS[ice-mods]//\'\'/}} ) nval_ices=( blockf silent lucid trackbinds cloneonly nocd run-atpull @@ -2932,12 +2933,12 @@ EOF # Include only those additional ices, # don't have the '' in their name, i.e. # aren't designed to hold value - ${(@)${(@s.|.)ZPLG_EXTS[ice-mods]}:#*\'\'*} + ${(@)${(@s.|.)ZINIT_EXTS[ice-mods]}:#*\'\'*} # Must be last svn ) - -zplg-compute-ice "$1${${1:#(%|/)*}:+${2:+/}}$2" "pack" \ + .zinit-compute-ice "$1${${1:#(%|/)*}:+${2:+/}}$2" "pack" \ ice local_dir filename is_snippet || return 1 [[ -e "$local_dir" ]] && { @@ -2955,115 +2956,115 @@ EOF if [[ "${#output}" = 0 ]]; then print -zr "# No Ice modifiers" else - print -zr "zplugin ice ${output[*]}; zplugin " + print -zr "zinit ice ${output[*]}; zinit " fi - -zplg-deploy-message @rst + .zinit-deploy-message @rst } || print -r -- "No such plugin or snippet" } -# }}} -# FUNCTION: -zplg-module {{{ +# >>> +# FUNCTION: .zinit-module <<< # Function that has sub-commands passed as long-options (with two dashes, --). -# It's an attempt to plugin only this one function into `zplugin' function -# defined in zplugin.zsh, to not make this file longer than it's needed. --zplg-module() { +# It's an attempt to plugin only this one function into `zinit' function +# defined in zinit.zsh, to not make this file longer than it's needed. +.zinit-module() { if [[ "$1" = "build" ]]; then - -zplg-build-module "${@[2,-1]}" + .zinit-build-module "${@[2,-1]}" elif [[ "$1" = "info" ]]; then if [[ "$2" = "--link" ]]; then print -r "You can copy the error messages and submit" - print -r "error-report at: https://github.com/zdharma/zplugin/issues" + print -r "error-report at: https://github.com/zdharma/zinit/issues" else print -r "To load the module, add following 2 lines to .zshrc, at top:" - print -r " module_path+=( \"${ZPLGM[BIN_DIR]}/zmodules/Src\" )" - print -r " zmodload zdharma/zplugin" + print -r " module_path+=( \"${ZINIT[BIN_DIR]}/zmodules/Src\" )" + print -r " zmodload zdharma/zinit" print -r "" print -r "After loading, use command \`zpmod' to communicate with the module." print -r "See \`zpmod -h' for more information." fi elif [[ "$1" = (help|usage) ]]; then - print -r "Usage: zplugin module {build|info|help} [options]" - print -r " zplugin module build [--clean]" - print -r " zplugin module info [--link]" + print -r "Usage: zinit module {build|info|help} [options]" + print -r " zinit module build [--clean]" + print -r " zinit module info [--link]" print -r "" - print -r "To start using the zplugin Zsh module run: \`zplugin module build'" + print -r "To start using the zinit Zsh module run: \`zinit module build'" print -r "and follow the instructions. Option --clean causes \`make distclean'" print -r "to be run. To display the instructions on loading the module, run:" - print -r "\`zplugin module info'." + print -r "\`zinit module info'." fi } -# }}} -# FUNCTION: -zplg-build-module {{{ +# >>> +# FUNCTION: .zinit-build-module <<< # Performs ./configure && make on the module and displays information # how to load the module in .zshrc. --zplg-build-module() { +.zinit-build-module() { setopt localoptions localtraps trap 'return 1' INT TERM - ( builtin cd -q "${ZPLGM[BIN_DIR]}"/zmodules - print -r -- "${ZPLGM[col-pname]}== Building module zdharma/zplugin, running: make clean, then ./configure and then make ==${ZPLGM[col-rst]}" - print -r -- "${ZPLGM[col-pname]}== The module sources are located at: "${ZPLGM[BIN_DIR]}"/zmodules ==${ZPLGM[col-rst]}" + ( builtin cd -q "${ZINIT[BIN_DIR]}"/zmodules + print -r -- "${ZINIT[col-pname]}== Building module zdharma/zinit, running: make clean, then ./configure and then make ==${ZINIT[col-rst]}" + print -r -- "${ZINIT[col-pname]}== The module sources are located at: "${ZINIT[BIN_DIR]}"/zmodules ==${ZINIT[col-rst]}" [[ -f Makefile ]] && { [[ "$1" = "--clean" ]] && { - print -r -- ${ZPLGM[col-p]}-- make distclean --${ZPLGM[col-rst]} + print -r -- ${ZINIT[col-p]}-- make distclean --${ZINIT[col-rst]} make distclean ((1)) } || { - print -r -- ${ZPLGM[col-p]}-- make clean --${ZPLGM[col-rst]} + print -r -- ${ZINIT[col-p]}-- make clean --${ZINIT[col-rst]} make clean } } - print -r -- ${ZPLGM[col-p]}-- ./configure --${ZPLGM[col-rst]} + print -r -- ${ZINIT[col-p]}-- ./configure --${ZINIT[col-rst]} CPPFLAGS=-I/usr/local/include CFLAGS="-g -Wall -O3" LDFLAGS=-L/usr/local/lib ./configure --disable-gdbm --without-tcsetpgrp && { - print -r -- ${ZPLGM[col-p]}-- make --${ZPLGM[col-rst]} + print -r -- ${ZINIT[col-p]}-- make --${ZINIT[col-rst]} make && { - [[ -f Src/zdharma/zplugin.so ]] && cp -vf Src/zdharma/zplugin.{so,bundle} - print -r -- "${ZPLGM[col-info]}Module has been built correctly.${ZPLGM[col-rst]}" - -zplg-module info + [[ -f Src/zdharma/zinit.so ]] && cp -vf Src/zdharma/zinit.{so,bundle} + print -r -- "${ZINIT[col-info]}Module has been built correctly.${ZINIT[col-rst]}" + .zinit-module info } || { - print -rn -- "${ZPLGM[col-error]}Module didn't build.${ZPLGM[col-rst]} " - -zplg-module info --link + print -rn -- "${ZINIT[col-error]}Module didn't build.${ZINIT[col-rst]} " + .zinit-module info --link } } ) } -# }}} +# >>> # # Help function # -# FUNCTION: -zplg-help {{{ +# FUNCTION: .zinit-help <<< # Shows usage information. # # User-action entry point. --zplg-help() { - print -r -- "${ZPLGM[col-p]}Usage${ZPLGM[col-rst]}: +.zinit-help() { + print -r -- "${ZINIT[col-p]}Usage${ZINIT[col-rst]}: β€”β€” -h|--help|help – usage information β€”β€” man – manual -β€”β€” self-update – updates and compiles Zplugin +β€”β€” self-update – updates and compiles Zinit β€”β€” times [-s] [-m] – statistics on plugin load times, sorted in order of loading; -s – use seconds instead of milliseconds, -m – show plugin loading moments -β€”β€” zstatus – overall Zplugin status -β€”β€” load ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – load plugin, can also receive absolute local path -β€”β€” light [-b] ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – light plugin load, without reporting/tracking (-b – do track but bindkey-calls only) -β€”β€” unload ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – unload plugin loaded with \`zplugin load ...', -q – quiet -β€”β€” snippet [-f] ${ZPLGM[col-pname]}{url}${ZPLGM[col-rst]} – source local or remote file (by direct URL), -f: force – don't use cache +β€”β€” zstatus – overall Zinit status +β€”β€” load ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – load plugin, can also receive absolute local path +β€”β€” light [-b] ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – light plugin load, without reporting/tracking (-b – do track but bindkey-calls only) +β€”β€” unload ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – unload plugin loaded with \`zinit load ...', -q – quiet +β€”β€” snippet [-f] ${ZINIT[col-pname]}{url}${ZINIT[col-rst]} – source local or remote file (by direct URL), -f: force – don't use cache β€”β€” ls – list snippets in formatted and colorized manner β€”β€” ice – add ICE to next command, argument is e.g. from\"gitlab\" -β€”β€” update [-q] ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]}|URL – Git update plugin or snippet (or all plugins and snippets if β€”β€”all passed); besides -q accepts also β€”β€”quiet, and also -r/--reset – this option causes to run git reset --hard / svn revert before pulling changes -β€”β€” status ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]}|URL – Git status for plugin or svn status for snippet (or for all those if β€”β€”all passed) -β€”β€” report ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – show plugin's report (or all plugins' if β€”β€”all passed) -β€”β€” delete [--all|--clean] ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]}|URL – remove plugin or snippet from disk (good to forget wrongly passed ice-mods); --all – purge, --clean – delete plugins and snippets that are not loaded +β€”β€” update [-q] ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]}|URL – Git update plugin or snippet (or all plugins and snippets if β€”β€”all passed); besides -q accepts also β€”β€”quiet, and also -r/--reset – this option causes to run git reset --hard / svn revert before pulling changes +β€”β€” status ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]}|URL – Git status for plugin or svn status for snippet (or for all those if β€”β€”all passed) +β€”β€” report ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – show plugin's report (or all plugins' if β€”β€”all passed) +β€”β€” delete [--all|--clean] ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]}|URL – remove plugin or snippet from disk (good to forget wrongly passed ice-mods); --all – purge, --clean – delete plugins and snippets that are not loaded β€”β€” loaded|list [keyword] – show what plugins are loaded (filter with \'keyword') -β€”β€” cd ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – cd into plugin's directory; also support snippets, if feed with URL -β€”β€” create ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – create plugin (also together with Github repository) -β€”β€” edit ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – edit plugin's file with \$EDITOR -β€”β€” glance ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – look at plugin's source (pygmentize, {,source-}highlight) -β€”β€” stress ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – test plugin for compatibility with set of options -β€”β€” changes ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – view plugin's git log -β€”β€” recently ${ZPLGM[col-info]}[time-spec]${ZPLGM[col-rst]} – show plugins that changed recently, argument is e.g. 1 month 2 days +β€”β€” cd ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – cd into plugin's directory; also support snippets, if feed with URL +β€”β€” create ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – create plugin (also together with Github repository) +β€”β€” edit ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – edit plugin's file with \$EDITOR +β€”β€” glance ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – look at plugin's source (pygmentize, {,source-}highlight) +β€”β€” stress ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – test plugin for compatibility with set of options +β€”β€” changes ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – view plugin's git log +β€”β€” recently ${ZINIT[col-info]}[time-spec]${ZINIT[col-rst]} – show plugins that changed recently, argument is e.g. 1 month 2 days β€”β€” clist|completions – list completions in use -β€”β€” cdisable ${ZPLGM[col-info]}cname${ZPLGM[col-rst]} – disable completion \`cname' -β€”β€” cenable ${ZPLGM[col-info]}cname${ZPLGM[col-rst]} – enable completion \`cname' -β€”β€” creinstall ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – install completions for plugin, can also receive absolute local path; -q – quiet -β€”β€” cuninstall ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – uninstall completions for plugin +β€”β€” cdisable ${ZINIT[col-info]}cname${ZINIT[col-rst]} – disable completion \`cname' +β€”β€” cenable ${ZINIT[col-info]}cname${ZINIT[col-rst]} – enable completion \`cname' +β€”β€” creinstall ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – install completions for plugin, can also receive absolute local path; -q – quiet +β€”β€” cuninstall ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – uninstall completions for plugin β€”β€” csearch – search for available completions from any plugin β€”β€” compinit – refresh installed completions β€”β€” dtrace|dstart – start tracking what's going on in session @@ -3071,29 +3072,29 @@ EOF β€”β€” dunload – revert changes recorded between dstart and dstop β€”β€” dreport – report what was going on in session β€”β€” dclear – clear report of what was going on in session -β€”β€” compile ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – compile plugin (or all plugins if β€”β€”all passed) -β€”β€” uncompile ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} – remove compiled version of plugin (or of all plugins if β€”β€”all passed) +β€”β€” compile ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – compile plugin (or all plugins if β€”β€”all passed) +β€”β€” uncompile ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} – remove compiled version of plugin (or of all plugins if β€”β€”all passed) β€”β€” compiled – list plugins that are compiled β€”β€” cdlist – show compdef replay list β€”β€” cdreplay [-q] – replay compdefs (to be done after compinit), -q – quiet β€”β€” cdclear [-q] – clear compdef replay list, -q – quiet β€”β€” srv {service-id} [cmd] – control a service, command can be: stop,start,restart,next,quit; \`next' moves the service to another Zshell -β€”β€” recall ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]}|URL – fetch saved ice modifiers and construct \`zplugin ice ...' command +β€”β€” recall ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]}|URL – fetch saved ice modifiers and construct \`zinit ice ...' command β€”β€” env-whitelist [-v|-h] {env..} – allows to specify names (also patterns) of variables left unchanged during an unload. -v – verbose β€”β€” bindkeys – lists bindkeys set up by each plugin -β€”β€” module – manage binary Zsh module shipped with Zplugin, see \`zplugin module help' -β€”β€” add-fpath|fpath ${ZPLGM[col-info]}[-f|--front]${ZPLGM[col-rst]} \\ - ${ZPLGM[col-pname]}plg-spec ${ZPLGM[col-info]}[subdirectory]${ZPLGM[col-rst]} – adds given plugin directory to \$fpath; if the second argument is given, it is appended to the directory path; if the option -f/--front is given, the directory path is prepended instead of appended to \$fpath. The ${ZPLGM[col-pname]}plg-spec${ZPLGM[col-rst]} can be absolute path +β€”β€” module – manage binary Zsh module shipped with Zinit, see \`zinit module help' +β€”β€” add-fpath|fpath ${ZINIT[col-info]}[-f|--front]${ZINIT[col-rst]} \\ + ${ZINIT[col-pname]}plg-spec ${ZINIT[col-info]}[subdirectory]${ZINIT[col-rst]} – adds given plugin directory to \$fpath; if the second argument is given, it is appended to the directory path; if the option -f/--front is given, the directory path is prepended instead of appended to \$fpath. The ${ZINIT[col-pname]}plg-spec${ZINIT[col-rst]} can be absolute path β€”β€” run [-l] [plugin] {command} – runs the given command in the given plugin's directory; if the option -l will be given then the plugin should be skipped – the option will cause the previous plugin to be reused" integer idx local type key local -a arr for type in subcommand hook; do - for (( idx=1; idx <= ZPLG_EXTS[seqno]; ++ idx )); do - key="${(k)ZPLG_EXTS[(r)$idx *]}" + for (( idx=1; idx <= ZINIT_EXTS[seqno]; ++ idx )); do + key="${(k)ZINIT_EXTS[(r)$idx *]}" [[ -z "$key" || "$key" != "z-annex $type:"* ]] && continue - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) (( ${+functions[${arr[6]}]} )) && { "${arr[6]}"; ((1)); } || \ { print -rl -- "(Couldn't find the help-handler \`${arr[6]}' of the z-annex \`${arr[3]}')"; } done @@ -3107,6 +3108,6 @@ Available ice-modifiers: cloneonly make service trackbinds multisrc compile nocompile nocompletions reset-prompt wrap-track reset aliases sh bash ksh csh countdown trigger-load light-mode is-snippet atdelete pack git verbose" -} # }}} +} # >>> -# vim:ft=zsh:sw=4:sts=4:et +# vim:ft=zsh:sw=4:sts=4:et:foldmarker=<<<,>>> diff --git a/zplugin-install.zsh b/zinit-install.zsh similarity index 60% rename from zplugin-install.zsh rename to zinit-install.zsh index 72c5a07d..470a4520 100644 --- a/zplugin-install.zsh +++ b/zinit-install.zsh @@ -1,12 +1,12 @@ # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # Copyright (c) 2019 Sebastian Gniazdowski and contributors -builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" +builtin source ${ZINIT[BIN_DIR]}"/zinit-side.zsh" -# FUNCTION: -zplg-parse-json {{{ +# FUNCTION: .zinit-parse-json <<< # Retrievies the ice-list from given profile from # the JSON of the package.json. --zplg-parse-json() { +.zinit-parse-json() { emulate -LR zsh setopt extendedglob warncreateglobal typesetsilent @@ -108,30 +108,30 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } if [[ -n $__found && $__nest -lt 2 ]] { - -zplg-parse-json "$__found" "$__key" "$__varname" 2 + .zinit-parse-json "$__found" "$__key" "$__varname" 2 } if (( __nest == 2 )) { : ${(PAA)__varname::="${(kv)__Strings[@]}"} } } -# }}} -# FUNCTION: -zplg-get-package {{{ --zplg-get-package() { +# >>> +# FUNCTION: .zinit-get-package <<< +.zinit-get-package() { emulate -LR zsh setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes local user="$1" plugin="$2" id_as="$3" dir="$4" profile="$5" \ - local_path="${ZPLGM[PLUGINS_DIR]}/${3//\//---}" pkgjson \ + local_path="${ZINIT[PLUGINS_DIR]}/${3//\//---}" pkgjson \ tmpfile="${$(mktemp):-/tmp/zsh.xYzAbc123}" \ URL="https://raw.githubusercontent.com/Zsh-Packages/$2/master/package.json" - print -r -- "Downloading ${ZPLGM[col-info2]}package.json${ZPLGM[col-rst]}" \ - "for ${ZPLGM[col-pname]}$plugin${ZPLGM[col-rst]}" + print -r -- "Downloading ${ZINIT[col-info2]}package.json${ZINIT[col-rst]}" \ + "for ${ZINIT[col-pname]}$plugin${ZINIT[col-rst]}" if [[ $profile != ./* ]]; then - -zplg-download-file-stdout $URL 2>/dev/null > $tmpfile || \ - { rm -f $tmpfile; -zplg-download-file-stdout $URL 1 2>/dev/null > $tmpfile } + .zinit-download-file-stdout $URL 2>/dev/null > $tmpfile || \ + { rm -f $tmpfile; .zinit-download-file-stdout $URL 1 2>/dev/null > $tmpfile } else tmpfile=${profile%:*} profile=${${${(M)profile:#*:*}:+${profile#*:}}:-default} @@ -140,14 +140,14 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" pkgjson="$(<$tmpfile)" if [[ -z $pkgjson ]]; then - print -r -- "${ZPLGM[col-error]}Error: the package $id_as couldn't be found" + print -r -- "${ZINIT[col-error]}Error: the package $id_as couldn't be found" return 1 fi - print -r -- "Parsing ${ZPLGM[col-info2]}package.json${ZPLGM[col-rst]}..." + print -r -- "Parsing ${ZINIT[col-info2]}package.json${ZINIT[col-rst]}..." local -A Strings - -zplg-parse-json "$pkgjson" "plugin-info" Strings + .zinit-parse-json "$pkgjson" "plugin-info" Strings local -A jsondata1 jsondata1=( ${(@Q)${(@z)Strings[2/1]}} ) @@ -163,75 +163,75 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" pos=${${(@Q)${(@z)Strings[2/2]}}[(I)$profile]} if (( pos )) { for key value ( "${(@Q)${(@z)Strings[3/$(( (pos + 1) / 2 ))]}}" ) { - (( ${+ZPLG_ICE[$key]} )) && [[ ${ZPLG_ICE[$key]} != +* ]] && continue - ZPLG_ICE[$key]=$value${ZPLG_ICE[$key]#+} + (( ${+ZINIT_ICE[$key]} )) && [[ ${ZINIT_ICE[$key]} != +* ]] && continue + ZINIT_ICE[$key]=$value${ZINIT_ICE[$key]#+} } - ZPLG_ICE=( "${(kv)ZPLG_ICE[@]//\\\"/\"}" ) - [[ ${ZPLG_ICE[as]} = program ]] && ZPLG_ICE[as]="command" - [[ -n ${ZPLG_ICE[on-update-of]} ]] && ZPLG_ICE[subscribe]="${ZPLG_ICE[subscribe]:-${ZPLG_ICE[on-update-of]}}" - [[ -n ${ZPLG_ICE[pick]} ]] && ZPLG_ICE[pick]="${ZPLG_ICE[pick]//\$ZPFX/${ZPFX%/}}" - [[ -n ${ZPLG_ICE[id-as]} ]] && { - -zplg-substitute 'ZPLG_ICE[id-as]' + ZINIT_ICE=( "${(kv)ZINIT_ICE[@]//\\\"/\"}" ) + [[ ${ZINIT_ICE[as]} = program ]] && ZINIT_ICE[as]="command" + [[ -n ${ZINIT_ICE[on-update-of]} ]] && ZINIT_ICE[subscribe]="${ZINIT_ICE[subscribe]:-${ZINIT_ICE[on-update-of]}}" + [[ -n ${ZINIT_ICE[pick]} ]] && ZINIT_ICE[pick]="${ZINIT_ICE[pick]//\$ZPFX/${ZPFX%/}}" + [[ -n ${ZINIT_ICE[id-as]} ]] && { + @zinit-substitute 'ZINIT_ICE[id-as]' local -A map map=( "\"" "\\\"" "\\" "\\" ) - eval "ZPLG_ICE[id-as]=\"${ZPLG_ICE[id-as]//(#m)[\"\\]/${map[$MATCH]}}\"" + eval "ZINIT_ICE[id-as]=\"${ZINIT_ICE[id-as]//(#m)[\"\\]/${map[$MATCH]}}\"" } } else { - print -P -r -- "${ZPLGM[col-error]}Error: the profile \`%F{221}$profile${ZPLGM[col-error]}' couldn't be found, aborting%f" + print -P -r -- "${ZINIT[col-error]}Error: the profile \`%F{221}$profile${ZINIT[col-error]}' couldn't be found, aborting%f" print -r -- "Available profiles are: ${(j:, :)${profiles[@]:#$profile}}" return 1 } - print -r -- "Found the profile \`${ZPLGM[col-pname]}$profile${ZPLGM[col-rst]}'" + print -r -- "Found the profile \`${ZINIT[col-pname]}$profile${ZINIT[col-rst]}'" - ZPLG_ICE[required]=${ZPLG_ICE[required]:-$ZPLG_ICE[requires]} + ZINIT_ICE[required]=${ZINIT_ICE[required]:-$ZINIT_ICE[requires]} local -a req - req=( ${(s.;.)${:-${required:+$required\;}${ZPLG_ICE[required]}}} ) + req=( ${(s.;.)${:-${required:+$required\;}${ZINIT_ICE[required]}}} ) for required ( $req ) { if [[ $required = bgn ]]; then - if [[ -z ${(k)ZPLG_EXTS[(r)<-> z-annex-data: z-a-bin-gem-node *]} ]]; then - print -P -- "${ZPLGM[col-error]}ERROR: the" \ - "${${${(MS)ZPLG_ICE[required]##(\;|(#s))$required(\;|(#e))}:+selected profile}:-package}" \ - "${${${(MS)ZPLG_ICE[required]##(\;|(#s))$required(\;|(#e))}:+\`${ZPLGM[col-pname]}$profile${ZPLGM[col-error]}\'}:-\\b}" \ + if [[ -z ${(k)ZINIT_EXTS[(r)<-> z-annex-data: z-a-bin-gem-node *]} ]]; then + print -P -- "${ZINIT[col-error]}ERROR: the" \ + "${${${(MS)ZINIT_ICE[required]##(\;|(#s))$required(\;|(#e))}:+selected profile}:-package}" \ + "${${${(MS)ZINIT_ICE[required]##(\;|(#s))$required(\;|(#e))}:+\`${ZINIT[col-pname]}$profile${ZINIT[col-error]}\'}:-\\b}" \ "requires" "Bin-Gem-Node annex" \ - "\nSee: %F{221}https://github.com/zplugin/z-a-bin-gem-node%f" + "\nSee: %F{221}https://github.com/zinit/z-a-bin-gem-node%f" print -r -- "Other available profiles are: ${(j:, :)${profiles[@]:#$profile}}" return 1 fi else if ! command -v $required &>/dev/null; then - print -P -- "${ZPLGM[col-error]}ERROR: the" \ - "${${${(MS)ZPLG_ICE[required]##(\;|(#s))$required(\;|(#e))}:+selected profile}:-package}" \ - "${${${(MS)ZPLG_ICE[required]##(\;|(#s))$required(\;|(#e))}:+\`${ZPLGM[col-pname]}$profile${ZPLGM[col-error]}\'}:-\\b}" \ + print -P -- "${ZINIT[col-error]}ERROR: the" \ + "${${${(MS)ZINIT_ICE[required]##(\;|(#s))$required(\;|(#e))}:+selected profile}:-package}" \ + "${${${(MS)ZINIT_ICE[required]##(\;|(#s))$required(\;|(#e))}:+\`${ZINIT[col-pname]}$profile${ZINIT[col-error]}\'}:-\\b}" \ "requires" \ - "\`${ZPLGM[col-pname]}$required${ZPLGM[col-error]}' command%f" + "\`${ZINIT[col-pname]}$required${ZINIT[col-error]}' command%f" print -r -- "Other available profiles are: ${(j:, :)${profiles[@]:#$profile}}" return 1 fi fi } - if [[ -n ${ZPLG_ICE[dl]} && -z ${(k)ZPLG_EXTS[(r)<-> z-annex-data: z-a-patch-dl *]} ]] { - print -- "\n${ZPLGM[col-error]}WARNING:${ZPLGM[col-msg2]} the profile uses" \ - "${ZPLGM[col-obj]}dl''${ZPLGM[col-msg2]} ice however there's no" \ - "${ZPLGM[col-obj2]}z-a-patch-dl${ZPLGM[col-msg2]} annex loaded" \ + if [[ -n ${ZINIT_ICE[dl]} && -z ${(k)ZINIT_EXTS[(r)<-> z-annex-data: z-a-patch-dl *]} ]] { + print -- "\n${ZINIT[col-error]}WARNING:${ZINIT[col-msg2]} the profile uses" \ + "${ZINIT[col-obj]}dl''${ZINIT[col-msg2]} ice however there's no" \ + "${ZINIT[col-obj2]}z-a-patch-dl${ZINIT[col-msg2]} annex loaded" \ "(the ice will be inactive, i.e.: no additional files will" \ - "be downloaded)${ZPLGM[col-rst]}" + "be downloaded)${ZINIT[col-rst]}" } - print -n -- \\n${jsondata1[version]:+${ZPLGM[col-pname]}Version: ${ZPLGM[col-info2]}${jsondata1[version]}${ZPLGM[col-rst]}\\n} + print -n -- \\n${jsondata1[version]:+${ZINIT[col-pname]}Version: ${ZINIT[col-info2]}${jsondata1[version]}${ZINIT[col-rst]}\\n} [[ -n ${jsondata1[message]} ]] && \ - print -- "${ZPLGM[col-info]}${jsondata1[message]}${ZPLGM[col-rst]}" + print -- "${ZINIT[col-info]}${jsondata1[message]}${ZINIT[col-rst]}" - (( ${+ZPLG_ICE[is-snippet]} )) && { + (( ${+ZINIT_ICE[is-snippet]} )) && { reply=( "" "$url" ) REPLY=snippet return 0 } - if (( !${+ZPLG_ICE[git]} && !${+ZPLG_ICE[from]} )) { + if (( !${+ZINIT_ICE[git]} && !${+ZINIT_ICE[from]} )) { ( - -zplg-parse-json "$pkgjson" "_from" Strings + .zinit-parse-json "$pkgjson" "_from" Strings local -A jsondata jsondata=( "${(@Q)${(@z)Strings[1/1]}}" ) @@ -239,30 +239,30 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" local fname="${${URL%%\?*}:t}" command mkdir -p $dir || { - print -r -- "${ZPLGM[col-error]}Couldn't create directory: \`$dir', aborting${ZPLGM[col-rst]}" + print -r -- "${ZINIT[col-error]}Couldn't create directory: \`$dir', aborting${ZINIT[col-rst]}" return 1 } builtin cd -q $dir || return 1 - print -r -- "Downloading tarball for ${ZPLGM[col-pname]}$plugin${ZPLGM[col-rst]}..." + print -r -- "Downloading tarball for ${ZINIT[col-pname]}$plugin${ZINIT[col-rst]}..." - -zplg-download-file-stdout "$URL" >! "$fname" || { - -zplg-download-file-stdout "$URL" 1 >! "$fname" || { + .zinit-download-file-stdout "$URL" >! "$fname" || { + .zinit-download-file-stdout "$URL" 1 >! "$fname" || { command rm -f "$fname" print -r "Download of \`$fname' failed. No available download tool? (one of: cURL, wget, lftp, lynx)" return 1 } } - zpextract "$fname" --move + ziextract "$fname" --move return 0 ) && { reply=( "$user" "$plugin" ) REPLY=tarball } } else { - reply=( "${ZPLG_ICE[user]:-$user}" "${ZPLG_ICE[plugin]:-$plugin}" ) - if [[ ${ZPLG_ICE[from]} = (|gh-r|github-rel) ]]; then + reply=( "${ZINIT_ICE[user]:-$user}" "${ZINIT_ICE[plugin]:-$plugin}" ) + if [[ ${ZINIT_ICE[from]} = (|gh-r|github-rel) ]]; then REPLY=github else REPLY=unknown @@ -271,20 +271,20 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" return $? } -# }}} -# FUNCTION: -zplg-setup-plugin-dir {{{ +# >>> +# FUNCTION: .zinit-setup-plugin-dir <<< # Clones given plugin into PLUGIN_DIR. Supports multiple # sites (respecting `from' and `proto' ice modifiers). # Invokes compilation of plugin's main file. # # $1 - user # $2 - plugin --zplg-setup-plugin-dir() { +.zinit-setup-plugin-dir() { emulate -LR zsh setopt extendedglob warncreateglobal noshortloops rcquotes local user=$1 plugin=$2 id_as=$3 remote_url_path=${1:+$1/}$2 \ - local_path=${ZPLGM[PLUGINS_DIR]}/${3//\//---} tpe=$4 update=$5 \ + local_path=${ZINIT[PLUGINS_DIR]}/${3//\//---} tpe=$4 update=$5 \ version=$6 local -A sites @@ -324,27 +324,27 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" [[ $tpe != tarball ]] && { [[ -z $update ]] && { - -zplg-any-colorify-as-uspl2 "$user" "$plugin" - print "\\nDownloading $REPLY...${ZPLG_ICE[id-as]:+ (as ${id_as}...)}" + .zinit-any-colorify-as-uspl2 "$user" "$plugin" + print "\\nDownloading $REPLY...${ZINIT_ICE[id-as]:+ (as ${id_as}...)}" } local site - [[ -n ${ZPLG_ICE[from]} ]] && site=${sites[${ZPLG_ICE[from]}]} - [[ -z $site && ${ZPLG_ICE[from]} = *(gh-r|github-rel)* ]] && { - site=${ZPLG_ICE[from]/(gh-r|github-re)/${sites[gh-r]}} + [[ -n ${ZINIT_ICE[from]} ]] && site=${sites[${ZINIT_ICE[from]}]} + [[ -z $site && ${ZINIT_ICE[from]} = *(gh-r|github-rel)* ]] && { + site=${ZINIT_ICE[from]/(gh-r|github-re)/${sites[gh-r]}} } } ( if [[ $site = *releases ]] { - local url=$site/${ZPLG_ICE[ver]} + local url=$site/${ZINIT_ICE[ver]} local -a list list2 - list=( ${(@f)"$( { -zplg-download-file-stdout $url || -zplg-download-file-stdout $url 1; } 2>/dev/null | \ + list=( ${(@f)"$( { .zinit-download-file-stdout $url || .zinit-download-file-stdout $url 1; } 2>/dev/null | \ command grep -o 'href=./'$remote_url_path'/releases/download/[^"]\+')"} ) list=( ${list[@]#href=?} ) - [[ -n ${ZPLG_ICE[bpick]} ]] && list=( ${(M)list[@]:#(#i)*/${~ZPLG_ICE[bpick]}} ) + [[ -n ${ZINIT_ICE[bpick]} ]] && list=( ${(M)list[@]:#(#i)*/${~ZINIT_ICE[bpick]}} ) [[ ${#list} -gt 1 ]] && { list2=( ${(M)list[@]:#(#i)*${~matchstr[$CPUTYPE]:-${CPUTYPE#(#i)(i|amd)}}*} ) @@ -368,8 +368,8 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" () { setopt localoptions noautopushd; builtin cd -q "$local_path"; } || return 1 url="https://github.com${list[1]}" print "(Requesting \`${list[1]:t}'${version:+, version $version}...)" - -zplg-download-file-stdout "$url" >! "${list[1]:t}" || { - -zplg-download-file-stdout "$url" 1 >! "${list[1]:t}" || { + .zinit-download-file-stdout "$url" >! "${list[1]:t}" || { + .zinit-download-file-stdout "$url" 1 >! "${list[1]:t}" || { command rm -f "${list[1]:t}" print -r "Download of release for \`$remote_url_path' failed. No available download tool? (one of: curl, wget, lftp, lynx)" print -r "Tried url: $url" @@ -377,57 +377,57 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } } - command mkdir -p ._zplugin - print -r -- $url >! ._zplugin/url - print -r -- ${list[1]} >! ._zplugin/is_release - zpextract ${list[1]:t} + command mkdir -p ._zinit + print -r -- $url >! ._zinit/url + print -r -- ${list[1]} >! ._zinit/is_release + ziextract ${list[1]:t} return $? ) || { return 1 } } elif [[ $tpe = github ]] { - case ${ZPLG_ICE[proto]} in + case ${ZINIT_ICE[proto]} in (|https) - command git clone --progress ${=ZPLG_ICE[cloneopts]:---recursive} \ - ${=ZPLG_ICE[depth]:+--depth ${ZPLG_ICE[depth]}} \ - "https://${site:-${ZPLG_ICE[from]:-github.com}}/$remote_url_path" \ + command git clone --progress ${=ZINIT_ICE[cloneopts]:---recursive} \ + ${=ZINIT_ICE[depth]:+--depth ${ZINIT_ICE[depth]}} \ + "https://${site:-${ZINIT_ICE[from]:-github.com}}/$remote_url_path" \ "$local_path" \ --config transfer.fsckobjects=false \ --config receive.fsckobjects=false \ --config fetch.fsckobjects=false \ - |& { ${ZPLGM[BIN_DIR]}/git-process-output.zsh || cat; } - (( pipestatus[1] )) && { print "${ZPLGM[col-error]}Clone failed (code: ${pipestatus[1]})${ZPLGM[col-rst]}"; return 1; } + |& { ${ZINIT[BIN_DIR]}/git-process-output.zsh || cat; } + (( pipestatus[1] )) && { print "${ZINIT[col-error]}Clone failed (code: ${pipestatus[1]})${ZINIT[col-rst]}"; return 1; } ;; (git|http|ftp|ftps|rsync|ssh) - command git clone --progress ${=ZPLG_ICE[cloneopts]:---recursive} \ - ${=ZPLG_ICE[depth]:+--depth ${ZPLG_ICE[depth]}} \ - "${ZPLG_ICE[proto]}://${site:-${ZPLG_ICE[from]:-github.com}}/$remote_url_path" \ + command git clone --progress ${=ZINIT_ICE[cloneopts]:---recursive} \ + ${=ZINIT_ICE[depth]:+--depth ${ZINIT_ICE[depth]}} \ + "${ZINIT_ICE[proto]}://${site:-${ZINIT_ICE[from]:-github.com}}/$remote_url_path" \ "$local_path" \ --config transfer.fsckobjects=false \ --config receive.fsckobjects=false \ --config fetch.fsckobjects=false \ - |& { ${ZPLGM[BIN_DIR]}/git-process-output.zsh || cat; } - (( pipestatus[1] )) && { print "${ZPLGM[col-error]}Clone failed (code: ${pipestatus[1]})${ZPLGM[col-rst]}"; return 1; } + |& { ${ZINIT[BIN_DIR]}/git-process-output.zsh || cat; } + (( pipestatus[1] )) && { print "${ZINIT[col-error]}Clone failed (code: ${pipestatus[1]})${ZINIT[col-rst]}"; return 1; } ;; (*) - print "${ZPLGM[col-error]}Unknown protocol:${ZPLGM[col-rst]} ${ZPLG_ICE[proto]}" + print "${ZINIT[col-error]}Unknown protocol:${ZINIT[col-rst]} ${ZINIT_ICE[proto]}" return 1 esac - if [[ -n ${ZPLG_ICE[ver]} ]] { - command git -C "$local_path" checkout "${ZPLG_ICE[ver]}" + if [[ -n ${ZINIT_ICE[ver]} ]] { + command git -C "$local_path" checkout "${ZINIT_ICE[ver]}" } } - [[ ${+ZPLG_ICE[make]} = 1 && ${ZPLG_ICE[make]} = "!!"* ]] && -zplg-countdown make && { local make=${ZPLG_ICE[make]}; -zplg-substitute make; command make -C "$local_path" ${(@s; ;)${make#\!\!}}; } + [[ ${+ZINIT_ICE[make]} = 1 && ${ZINIT_ICE[make]} = "!!"* ]] && .zinit-countdown make && { local make=${ZINIT_ICE[make]}; @zinit-substitute make; command make -C "$local_path" ${(@s; ;)${make#\!\!}}; } - if [[ -n ${ZPLG_ICE[mv]} ]] { - if [[ ${ZPLG_ICE[mv]} = *("->"|"β†’")* ]] { - local from=${ZPLG_ICE[mv]%%[[:space:]]#(->|β†’)*} to=${ZPLG_ICE[mv]##*(->|β†’)[[:space:]]#} || \ + if [[ -n ${ZINIT_ICE[mv]} ]] { + if [[ ${ZINIT_ICE[mv]} = *("->"|"β†’")* ]] { + local from=${ZINIT_ICE[mv]%%[[:space:]]#(->|β†’)*} to=${ZINIT_ICE[mv]##*(->|β†’)[[:space:]]#} || \ } else { - local from=${ZPLG_ICE[mv]%%[[:space:]]##*} to=${ZPLG_ICE[mv]##*[[:space:]]##} + local from=${ZINIT_ICE[mv]%%[[:space:]]##*} to=${ZINIT_ICE[mv]##*[[:space:]]##} } - -zplg-substitute from to + @zinit-substitute from to local -a afr ( () { setopt localoptions noautopushd; builtin cd -q "$local_path"; } || return 1 afr=( ${~from}(DN) ) @@ -443,13 +443,13 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" ) } - if [[ -n ${ZPLG_ICE[cp]} ]] { - if [[ ${ZPLG_ICE[cp]} = *("->"|"β†’")* ]] { - local from=${ZPLG_ICE[cp]%%[[:space:]]#(->|β†’)*} to=${ZPLG_ICE[cp]##*(->|β†’)[[:space:]]#} || \ + if [[ -n ${ZINIT_ICE[cp]} ]] { + if [[ ${ZINIT_ICE[cp]} = *("->"|"β†’")* ]] { + local from=${ZINIT_ICE[cp]%%[[:space:]]#(->|β†’)*} to=${ZINIT_ICE[cp]##*(->|β†’)[[:space:]]#} || \ } else { - local from=${ZPLG_ICE[cp]%%[[:space:]]##*} to=${ZPLG_ICE[cp]##*[[:space:]]##} + local from=${ZINIT_ICE[cp]%%[[:space:]]##*} to=${ZINIT_ICE[cp]##*[[:space:]]##} } - -zplg-substitute from to + @zinit-substitute from to local -a afr ( () { setopt localoptions noautopushd; builtin cd -q "$local_path"; } || return 1 afr=( ${~from}(DN) ) @@ -465,52 +465,52 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" ) } - if [[ $site != *releases && ${ZPLG_ICE[nocompile]} != '!' ]] { + if [[ $site != *releases && ${ZINIT_ICE[nocompile]} != '!' ]] { # Compile plugin - [[ -z ${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && { - -zplg-compile-plugin "$id_as" "" + [[ -z ${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && { + .zinit-compile-plugin "$id_as" "" } } if [[ $4 != -u ]] { # Store ices at clone of a plugin - -zplg-store-ices "$local_path/._zplugin" ZPLG_ICE "" "" "" "" + .zinit-store-ices "$local_path/._zinit" ZINIT_ICE "" "" "" "" - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atclone <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atclone <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "plugin" "$user" "$plugin" "$id_as" "$local_path" \!atclone done - local atclone=${ZPLG_ICE[atclone]} - [[ -n $atclone ]] && -zplg-substitute atclone + local atclone=${ZINIT_ICE[atclone]} + [[ -n $atclone ]] && @zinit-substitute atclone - [[ ${+ZPLG_ICE[make]} = 1 && ${ZPLG_ICE[make]} = ("!"[^\!]*|"!") ]] && -zplg-countdown make && { local make=${ZPLG_ICE[make]}; -zplg-substitute make; command make -C "$local_path" ${(@s; ;)${make#\!}}; } - (( ${+ZPLG_ICE[atclone]} )) && -zplg-countdown "atclone" && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_path"; } && eval "$atclone"; ((1)); } || eval "$atclone"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - [[ ${+ZPLG_ICE[make]} = 1 && ${ZPLG_ICE[make]} != "!"* ]] && -zplg-countdown make && { local make=${ZPLG_ICE[make]}; -zplg-substitute make; command make -C "$local_path" ${(@s; ;)make}; } + [[ ${+ZINIT_ICE[make]} = 1 && ${ZINIT_ICE[make]} = ("!"[^\!]*|"!") ]] && .zinit-countdown make && { local make=${ZINIT_ICE[make]}; @zinit-substitute make; command make -C "$local_path" ${(@s; ;)${make#\!}}; } + (( ${+ZINIT_ICE[atclone]} )) && .zinit-countdown "atclone" && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_path"; } && eval "$atclone"; ((1)); } || eval "$atclone"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + [[ ${+ZINIT_ICE[make]} = 1 && ${ZINIT_ICE[make]} != "!"* ]] && .zinit-countdown make && { local make=${ZINIT_ICE[make]}; @zinit-substitute make; command make -C "$local_path" ${(@s; ;)make}; } - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atclone <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atclone <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "plugin" "$user" "$plugin" "$id_as" "$local_path" atclone done } # After additional executions like atclone'' - install completions (1 - plugins) - [[ 1 = ${+ZPLG_ICE[nocompletions]} || ${ZPLG_ICE[as]} = null ]] || -zplg-install-completions "$id_as" "" "0" ${ZPLG_ICE[silent]+-q} + [[ 1 = ${+ZINIT_ICE[nocompletions]} || ${ZINIT_ICE[as]} = null ]] || .zinit-install-completions "$id_as" "" "0" ${ZINIT_ICE[silent]+-q} - if [[ $site != *releases && ${ZPLG_ICE[nocompile]} = '!' ]] { + if [[ $site != *releases && ${ZINIT_ICE[nocompile]} = '!' ]] { # Compile plugin LANG=C sleep 0.3 - [[ -z ${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && { - -zplg-compile-plugin "$id_as" "" + [[ -z ${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && { + .zinit-compile-plugin "$id_as" "" } } ) || return $? return 0 -} # }}} -# FUNCTION: -zplg-install-completions {{{ +} # >>> +# FUNCTION: .zinit-install-completions <<< # Installs all completions of given plugin. After that they are # visible to `compinit'. Visible completions can be selectively # disabled and enabled. User can access completion data with @@ -519,7 +519,7 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) # $3 - if 1, then reinstall, otherwise only install completions that aren't there --zplg-install-completions() { +.zinit-install-completions() { builtin setopt localoptions nullglob extendedglob unset nokshglob warncreateglobal # $id_as - a /-separated pair if second element @@ -528,22 +528,22 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" local id_as="$1${2:+${${${(M)1:#%}:+$2}:-/$2}}" reinstall="${3:-0}" quiet="${${4:+1}:-0}" (( ICE_OPTS[opt_-q,--quiet] )) && quiet=1 - -zplg-any-to-user-plugin "$id_as" "" + .zinit-any-to-user-plugin "$id_as" "" local user="${reply[-2]}" local plugin="${reply[-1]}" - -zplg-any-colorify-as-uspl2 "$user" "$plugin" + .zinit-any-colorify-as-uspl2 "$user" "$plugin" local abbrev_pspec="$REPLY" - -zplg-exists-physically-message "$id_as" "" || return 1 + .zinit-exists-physically-message "$id_as" "" || return 1 # Symlink any completion files included in plugin's directory typeset -a completions already_symlinked backup_comps local c cfile bkpfile [[ "$user" = "%" ]] && \ completions=( "${plugin}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN^/) ) || \ - completions=( "${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN^/) ) - already_symlinked=( "${ZPLGM[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc(DN) ) - backup_comps=( "${ZPLGM[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN) ) + completions=( "${ZINIT[PLUGINS_DIR]}/${id_as//\//---}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|_zsh_highlight*|/zsdoc/*)(DN^/) ) + already_symlinked=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc(DN) ) + backup_comps=( "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN) ) # Symlink completions if they are not already there # either as completions (_fname) or as backups (fname) @@ -557,35 +557,35 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" ]]; then if [[ "$reinstall" = "1" ]]; then # Remove old files - command rm -f "${ZPLGM[COMPLETIONS_DIR]}/$cfile" - command rm -f "${ZPLGM[COMPLETIONS_DIR]}/$bkpfile" + command rm -f "${ZINIT[COMPLETIONS_DIR]}/$cfile" + command rm -f "${ZINIT[COMPLETIONS_DIR]}/$bkpfile" fi - (( quiet )) || print "Symlinking completion ${ZPLGM[col-uname]}$cfile${ZPLGM[col-rst]} to completions directory" - command ln -s "$c" "${ZPLGM[COMPLETIONS_DIR]}/$cfile" + (( quiet )) || print "Symlinking completion ${ZINIT[col-uname]}$cfile${ZINIT[col-rst]} to completions directory" + command ln -s "$c" "${ZINIT[COMPLETIONS_DIR]}/$cfile" # Make compinit notice the change - -zplg-forget-completion "$cfile" "$quiet" + .zinit-forget-completion "$cfile" "$quiet" else (( quiet )) || print "Not symlinking completion \`$cfile', it already exists" - (( quiet )) || print "${ZPLGM[col-info2]}Use \`${ZPLGM[col-pname]}zplugin creinstall $abbrev_pspec${ZPLGM[col-info2]}' to force install${ZPLGM[col-rst]}" + (( quiet )) || print "${ZINIT[col-info2]}Use \`${ZINIT[col-pname]}zinit creinstall $abbrev_pspec${ZINIT[col-info2]}' to force install${ZINIT[col-rst]}" fi done - -zplg-compinit &>/dev/null -} # }}} -# FUNCTION: -zplg-compinit {{{ + .zinit-compinit &>/dev/null +} # >>> +# FUNCTION: .zinit-compinit <<< # User-exposed `compinit' frontend which first ensures that all -# completions managed by Zplugin are forgotten by Zshell. After +# completions managed by Zinit are forgotten by Zshell. After # that it runs normal `compinit', which should more easily detect -# Zplugin's completions. +# Zinit's completions. # # No arguments. --zplg-compinit() { +.zinit-compinit() { builtin setopt localoptions nullglob extendedglob nokshglob noksharrays warncreateglobal typeset -a symlinked backup_comps local c cfile bkpfile action - symlinked=( "${ZPLGM[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc ) - backup_comps=( "${ZPLGM[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) + symlinked=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc ) + backup_comps=( "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc ) # Delete completions if they are really there, either # as completions (_fname) or backups (fname) @@ -595,23 +595,23 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" cfile="_${cfile#_}" bkpfile="${cfile#_}" - #print "${ZPLGM[col-info]}Processing completion $cfile${ZPLGM[col-rst]}" - -zplg-forget-completion "$cfile" + #print "${ZINIT[col-info]}Processing completion $cfile${ZINIT[col-rst]}" + .zinit-forget-completion "$cfile" done print "Initializing completion (compinit)..." - command rm -f ${ZPLGM[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} + command rm -f ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} # Workaround for a nasty trick in _vim (( ${+functions[_vim_files]} )) && unfunction _vim_files builtin autoload -Uz compinit - compinit -d ${ZPLGM[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZPLGM[COMPINIT_OPTS]}}" -} # }}} -# FUNCTION: -zplg-download-file-stdout {{{ + compinit -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}" +} # >>> +# FUNCTION: .zinit-download-file-stdout <<< # Downloads file to stdout. Supports following backend commands: # curl, wget, lftp, lynx. Used by snippet loading. --zplg-download-file-stdout() { +.zinit-download-file-stdout() { local url="$1" restart="$2" setopt localoptions localtraps @@ -642,17 +642,17 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" elif type lftp 2>/dev/null 1>&2; then command lftp -c "cat $url" || return 1 else - -zplg-download-file-stdout "$url" "1" + .zinit-download-file-stdout "$url" "1" return $? fi fi return 0 -} # }}} -# FUNCTION: -zplg-get-url-mtime {{{ +} # >>> +# FUNCTION: .zinit-get-url-mtime <<< # For the given URL returns the date in the Last-Modified # header as a time stamp --zplg-get-url-mtime() { +.zinit-get-url-mtime() { local url="$1" IFS line header local -a cmd @@ -688,8 +688,8 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } return 0 -} # }}} -# FUNCTION: -zplg-mirror-using-svn {{{ +} # >>> +# FUNCTION: .zinit-mirror-using-svn <<< # Used to clone subdirectories from Github. If in update mode # (see $2), then invokes `svn update', in normal mode invokes # `svn checkout --non-interactive -q '. In test mode only @@ -699,11 +699,11 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" # $1 - URL # $2 - mode, "" - normal, "-u" - update, "-t" - test # $3 - subdirectory (not path) with working copy, needed for -t and -u --zplg-mirror-using-svn() { +.zinit-mirror-using-svn() { setopt localoptions extendedglob warncreateglobal local url="$1" update="$2" directory="$3" - (( ${+commands[svn]} )) || print -r -- "${ZPLGM[col-error]}Warning:${ZPLGM[col-rst]} Subversion not found, please install it to use \`svn' ice-mod" + (( ${+commands[svn]} )) || print -r -- "${ZINIT[col-error]}Warning:${ZINIT[col-rst]} Subversion not found, please install it to use \`svn' ice-mod" if [[ "$update" = "-t" ]]; then ( @@ -728,39 +728,39 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" fi return $? } -# }}} -# FUNCTION: -zplg-forget-completion {{{ +# >>> +# FUNCTION: .zinit-forget-completion <<< # Implements alternation of Zsh state so that already initialized # completion stops being visible to Zsh. # # $1 - completion function name, e.g. "_cp"; can also be "cp" --zplg-forget-completion() { +.zinit-forget-completion() { local f="$1" quiet="$2" typeset -a commands commands=( "${(k@)_comps[(R)$f]}" ) # TODO: "${${(k)_comps[(R)$f]}[@]}" ? - [[ "${#commands}" -gt 0 ]] && (( quiet == 0 )) && print -n "Forgetting commands completed by \`${ZPLGM[col-pname]}$f${ZPLGM[col-rst]}': " + [[ "${#commands}" -gt 0 ]] && (( quiet == 0 )) && print -n "Forgetting commands completed by \`${ZINIT[col-pname]}$f${ZINIT[col-rst]}': " local k integer first=1 for k in "${commands[@]}"; do [[ -n "$k" ]] || continue unset "_comps[$k]" - (( quiet )) || print -n "${${first:#1}:+, }${ZPLGM[col-info]}$k${ZPLGM[col-rst]}" + (( quiet )) || print -n "${${first:#1}:+, }${ZINIT[col-info]}$k${ZINIT[col-rst]}" first=0 done (( quiet || first )) || print unfunction -- 2>/dev/null "$f" -} # }}} -# FUNCTION: -zplg-compile-plugin {{{ +} # >>> +# FUNCTION: .zinit-compile-plugin <<< # Compiles given plugin (its main source file, and also an # additional "....zsh" file if it exists). # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-compile-plugin() { +.zinit-compile-plugin() { # $id_as - a /-separated pair if second element # is not empty and first is not "%" - then it's # just $1 in first case, or $1$2 in second case @@ -768,7 +768,7 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" local -a list local -A ICE - -zplg-compute-ice "$id_as" "pack" \ + .zinit-compute-ice "$id_as" "pack" \ ICE plugin_dir filename is_snippet || return 1 [[ "${ICE[pick]}" = "/dev/null" ]] && return 0 @@ -783,12 +783,12 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" reply=( "${list[1]:h}" "${list[1]}" ) else if (( is_snippet )) { - -zplg-first "%" "$plugin_dir" || { + .zinit-first "%" "$plugin_dir" || { print "No files for compilation found" return 1 } } else { - -zplg-first "$1" "$2" || { + .zinit-first "$1" "$2" || { print "No files for compilation found" return 1 } @@ -798,11 +798,11 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" first="${reply[-1]}" local fname="${first#$pdir_path/}" - print "Compiling ${ZPLGM[col-info]}$fname${ZPLGM[col-rst]}..." + print "Compiling ${ZINIT[col-info]}$fname${ZINIT[col-rst]}..." [[ -z ${ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && { zcompile "$first" || { print "Compilation failed. Don't worry, the plugin will work also without compilation" - print "Consider submitting an error report to Zplugin or to the plugin's author" + print "Consider submitting an error report to Zinit or to the plugin's author" } } # Try to catch possible additional file @@ -817,19 +817,19 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" for first in "${list[@]}"; do zcompile "$first" done - local sep="${ZPLGM[col-pname]},${ZPLGM[col-rst]} " - print "Compiled following additional files (${ZPLGM[col-pname]}the compile''-ice${ZPLGM[col-rst]}): ${(pj:$sep:)${(@)${list[@]//(#b).([^.\/]##(#e))/.${ZPLGM[col-info]}${match[1]}${ZPLGM[col-rst]}}#$plugin_dir/}}" + local sep="${ZINIT[col-pname]},${ZINIT[col-rst]} " + print "Compiled following additional files (${ZINIT[col-pname]}the compile''-ice${ZINIT[col-rst]}): ${(pj:$sep:)${(@)${list[@]//(#b).([^.\/]##(#e))/.${ZINIT[col-info]}${match[1]}${ZINIT[col-rst]}}#$plugin_dir/}}" } fi return 0 -} # }}} -# FUNCTION: -zplg-download-snippet {{{ +} # >>> +# FUNCTION: .zinit-download-snippet <<< # Downloads snippet – either a file – with curl, wget, lftp or lynx, # or a directory, with Subversion – when svn-ICE is active. Github # supports Subversion protocol and allows to clone subdirectories. # This is used to provide a layer of support for Oh-My-Zsh and Prezto. --zplg-download-snippet() { +.zinit-download-snippet() { emulate -LR zsh setopt extendedglob warncreateglobal noshortloops @@ -842,14 +842,14 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } || local sname="$id_as_clean" # Change the url to point to raw github content if it isn't like that - [[ "$url" = *github.com* && ! "$url" = */raw/* && "${+ZPLG_ICE[svn]}" = "0" ]] && url="${url/\/blob\///raw/}" + [[ "$url" = *github.com* && ! "$url" = */raw/* && "${+ZINIT_ICE[svn]}" = "0" ]] && url="${url/\/blob\///raw/}" if [[ ! -d "$local_dir/$dirname" ]]; then - [[ "$update" != "-u" ]] && print "\n${ZPLGM[col-info]}Setting up snippet ${ZPLGM[col-p]}${(l:10:: :)}$sname${ZPLGM[col-rst]}${ZPLG_ICE[id-as]:+... (as $id_as)}" + [[ "$update" != "-u" ]] && print "\n${ZINIT[col-info]}Setting up snippet ${ZINIT[col-p]}${(l:10:: :)}$sname${ZINIT[col-rst]}${ZINIT_ICE[id-as]:+... (as $id_as)}" command mkdir -p "$local_dir" fi - [[ "$update" = "-u" && "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -r -- $'\n'"${ZPLGM[col-info]}Updating snippet ${ZPLGM[col-p]}$sname${ZPLGM[col-rst]}${ZPLG_ICE[id-as]:+... (identified as $id_as)}" + [[ "$update" = "-u" && "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -r -- $'\n'"${ZINIT[col-info]}Updating snippet ${ZINIT[col-p]}$sname${ZINIT[col-rst]}${ZINIT_ICE[id-as]:+... (identified as $id_as)}" ( if [[ "$url" = (http|https|ftp|ftps|scp)://* ]] { @@ -857,14 +857,14 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" ( () { setopt localoptions noautopushd; builtin cd -q "$local_dir"; } || return 1 - [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print "Downloading \`$sname'${${ZPLG_ICE[svn]+ \(with Subversion\)}:- \(with curl, wget, lftp\)}..." + [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print "Downloading \`$sname'${${ZINIT_ICE[svn]+ \(with Subversion\)}:- \(with curl, wget, lftp\)}..." - if (( ${+ZPLG_ICE[svn]} )) { + if (( ${+ZINIT_ICE[svn]} )) { local skip_pull=0 if [[ "$update" = "-u" ]] { # Test if update available - -zplg-mirror-using-svn "$url" "-t" "$dirname" || { - (( ${+ZPLG_ICE[run-atpull]} )) && { + .zinit-mirror-using-svn "$url" "-t" "$dirname" || { + (( ${+ZINIT_ICE[run-atpull]} )) && { skip_pull=1 } || return 2 } @@ -875,41 +875,41 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } # Run annexes' atpull hooks (the before atpull-ice ones) - [[ ${ZPLG_ICE[atpull][1]} = *"!"* ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) + [[ ${ZINIT_ICE[atpull][1]} = *"!"* ]] && { + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" \!atpull done } - (( ${+ZPLG_ICE[reset]} )) && ( - [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZPLG_ICE[reset]:-svn revert --recursive $filename/.}%f" - eval "${ZPLG_ICE[reset]:-command svn revert --recursive $filename/.}" + (( ${+ZINIT_ICE[reset]} )) && ( + [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZINIT_ICE[reset]:-svn revert --recursive $filename/.}%f" + eval "${ZINIT_ICE[reset]:-command svn revert --recursive $filename/.}" ) - [[ ${ZPLG_ICE[atpull][1]} = *"!"* ]] && -zplg-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; ((1)); } || -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} + [[ ${ZINIT_ICE[atpull][1]} = *"!"* ]] && .zinit-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; ((1)); } || .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} if (( !skip_pull )) { # Do the update # The condition is reversed on purpose – to show only # the messages on an actual update [[ "${ICE_OPTS[opt_-q,--quiet]}" = 1 ]] && { - print -r -- $'\n'"${ZPLGM[col-info]}Updating snippet ${ZPLGM[col-p]}$sname${ZPLGM[col-rst]}${ZPLG_ICE[id-as]:+... (identified as $id_as)}" - print "Downloading \`$sname'${${ZPLG_ICE[svn]+ \(with Subversion\)}:- \(with wget, curl, lftp\)}..." + print -r -- $'\n'"${ZINIT[col-info]}Updating snippet ${ZINIT[col-p]}$sname${ZINIT[col-rst]}${ZINIT_ICE[id-as]:+... (identified as $id_as)}" + print "Downloading \`$sname'${${ZINIT_ICE[svn]+ \(with Subversion\)}:- \(with wget, curl, lftp\)}..." } - -zplg-mirror-using-svn "$url" "-u" "$dirname" || return 1 + .zinit-mirror-using-svn "$url" "-u" "$dirname" || return 1 } } else { - -zplg-mirror-using-svn "$url" "" "$dirname" || return 1 + .zinit-mirror-using-svn "$url" "" "$dirname" || return 1 } # Redundant code, just to compile SVN snippet - if [[ ${ZPLG_ICE[as]} != "command" ]]; then - if [[ -n ${ZPLG_ICE[pick]} ]]; then - list=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZPLG_ICE[pick]}(DN) ) - elif [[ -z ${ZPLG_ICE[pick]} ]]; then + if [[ ${ZINIT_ICE[as]} != "command" ]]; then + if [[ -n ${ZINIT_ICE[pick]} ]]; then + list=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZINIT_ICE[pick]}(DN) ) + elif [[ -z ${ZINIT_ICE[pick]} ]]; then list=( $local_dir/$dirname/*.plugin.zsh(DN) $local_dir/$dirname/*.zsh-theme(DN) $local_dir/$dirname/init.zsh(DN) $local_dir/$dirname/*.zsh(DN) $local_dir/$dirname/*.sh(DN) $local_dir/$dirname/.zshrc(DN) @@ -917,9 +917,9 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" fi [[ -e "${list[1]}" && "${list[1]}" != */dev/null && \ - -z ${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && \ + -z ${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && \ { - (( !${+ZPLG_ICE[nocompile]} )) && { + (( !${+ZINIT_ICE[nocompile]} )) && { zcompile "${list[1]}" &>/dev/null || { print -r "Warning: couldn't compile \`${list[1]}'" } @@ -930,7 +930,7 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" command mkdir -p "$local_dir/$dirname" if (( !ICE_OPTS[opt_-f,--force] )) { - -zplg-get-url-mtime "$url" + .zinit-get-url-mtime "$url" } else { REPLY=$EPOCHSECONDS } @@ -946,7 +946,7 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" local -a matched matched=( "$local_dir"/"$dirname"/"$filename"(DNms-$secs) ) (( ${#matched} )) && { - (( ${+ZPLG_ICE[run-atpull]} )) && skip_dl=1 || return 2 + (( ${+ZINIT_ICE[run-atpull]} )) && skip_dl=1 || return 2 } if (( !skip_dl )) { @@ -957,19 +957,19 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } # Run annexes' atpull hooks (the before atpull-ice ones) - [[ "$update" = "-u" && ${ZPLG_ICE[atpull][1]} = *"!"* ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) + [[ "$update" = "-u" && ${ZINIT_ICE[atpull][1]} = *"!"* ]] && { + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" \!atpull done } - [[ "$update" = "-u" && ${ZPLG_ICE[atpull][1]} = *"!"* ]] && -zplg-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; ((1)); } || -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} + [[ "$update" = "-u" && ${ZINIT_ICE[atpull][1]} = *"!"* ]] && .zinit-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; ((1)); } || .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} if (( !skip_dl )) { - -zplg-download-file-stdout "$url" >! "$dirname/$filename" || { - -zplg-download-file-stdout "$url" 1 >! "$dirname/$filename" || { + .zinit-download-file-stdout "$url" >! "$dirname/$filename" || { + .zinit-download-file-stdout "$url" 1 >! "$dirname/$filename" || { command rm -f "$dirname/$filename" print -r "Download failed. No available download tool? (one of: curl, wget, lftp, lynx)" return 1 @@ -980,8 +980,8 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" return 0 ) || retval=$? - if [[ -n "${ZPLG_ICE[compile]}" ]]; then - list=( ${(M)~ZPLG_ICE[compile]##/*}(DN) $local_dir/$dirname/${~ZPLG_ICE[compile]}(DN) ) + if [[ -n "${ZINIT_ICE[compile]}" ]]; then + list=( ${(M)~ZINIT_ICE[compile]##/*}(DN) $local_dir/$dirname/${~ZINIT_ICE[compile]}(DN) ) [[ ${#list} -eq 0 ]] && { print "Warning: Ice-mod compile'' didn't match any files" } || { @@ -993,18 +993,18 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } fi - if [[ $ZPLG_ICE[as] != "command" ]] && (( ${+ZPLG_ICE[svn]} == 0 )); then + if [[ $ZINIT_ICE[as] != "command" ]] && (( ${+ZINIT_ICE[svn]} == 0 )); then local file_path="$local_dir/$dirname/$filename" - if [[ -n "${ZPLG_ICE[pick]}" ]]; then - list=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZPLG_ICE[pick]}(DN) ) + if [[ -n "${ZINIT_ICE[pick]}" ]]; then + list=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZINIT_ICE[pick]}(DN) ) file_path="${list[1]}" fi - [[ -e $file_path && -z ${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]} && $file_path != */dev/null ]] && { - (( !${+ZPLG_ICE[nocompile]} )) && { + [[ -e $file_path && -z ${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]} && $file_path != */dev/null ]] && { + (( !${+ZINIT_ICE[nocompile]} )) && { zcompile "$file_path" 2>/dev/null || { print -r "Couldn't compile \`${file_path:t}', it MIGHT be wrongly downloaded" print -r "(snippet URL points to a directory instead of a file?" - print -r "to download directory, use preceding: zplugin ice svn)" + print -r "to download directory, use preceding: zinit ice svn)" retval=0 } } @@ -1018,81 +1018,81 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" } # Run annexes' atpull hooks (the before atpull-ice ones) - [[ "$update" = "-u" && ${ZPLG_ICE[atpull][1]} = *"!"* ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) + [[ "$update" = "-u" && ${ZINIT_ICE[atpull][1]} = *"!"* ]] && { + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" \!atpull done } - (( ${+ZPLG_ICE[reset]} )) && ( - [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZPLG_ICE[reset]:-rm -f $local_dir/$dirname/$filename}%f" - eval "${ZPLG_ICE[reset]:-command rm -f $local_dir/$dirname/$filename}" + (( ${+ZINIT_ICE[reset]} )) && ( + [[ "${ICE_OPTS[opt_-q,--quiet]}" != 1 ]] && print -P "%F{220}reset: running ${ZINIT_ICE[reset]:-rm -f $local_dir/$dirname/$filename}%f" + eval "${ZINIT_ICE[reset]:-command rm -f $local_dir/$dirname/$filename}" ) - [[ "$update" = "-u" && ${ZPLG_ICE[atpull][1]} = *"!"* ]] && -zplg-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; ((1)); } || -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} + [[ "$update" = "-u" && ${ZINIT_ICE[atpull][1]} = *"!"* ]] && .zinit-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; ((1)); } || .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} # Currently redundant, but theoretically it has its place [[ -f "$local_dir/$dirname/$filename" ]] && command rm -f "$local_dir/$dirname/$filename" command mkdir -p "$local_dir/$dirname" if (( !ICE_OPTS[opt_-q,--quiet] )) { - print -P "${ZPLGM[col-msg1]}Copying ${ZPLGM[col-obj]}$filename${ZPLGM[col-msg1]}...%f" + print -P "${ZINIT[col-msg1]}Copying ${ZINIT[col-obj]}$filename${ZINIT[col-msg1]}...%f" command cp -v "$url" "$local_dir/$dirname/$filename" || \ - { print -r -- "${ZPLGM[col-error]}An error occured${ZPLGM[col-rst]}"; retval=1; } + { print -r -- "${ZINIT[col-error]}An error occured${ZINIT[col-rst]}"; retval=1; } } else { command cp "$url" "$local_dir/$dirname/$filename" || \ - { print -r -- "${ZPLGM[col-error]}An error occured${ZPLGM[col-rst]}"; retval=1; } + { print -r -- "${ZINIT[col-error]}An error occured${ZINIT[col-rst]}"; retval=1; } } } - if [[ "${${:-$local_dir/$dirname}%%/##}" != "${ZPLGM[SNIPPETS_DIR]}" ]]; then + if [[ "${${:-$local_dir/$dirname}%%/##}" != "${ZINIT[SNIPPETS_DIR]}" ]]; then # Store ices at "clone" and update of snippet, SVN and single-file - local pfx="$local_dir/$dirname/._zplugin" - -zplg-store-ices "$pfx" ZPLG_ICE "url_rsvd" "" "$save_url" "${+ZPLG_ICE[svn]}" + local pfx="$local_dir/$dirname/._zinit" + .zinit-store-ices "$pfx" ZINIT_ICE "url_rsvd" "" "$save_url" "${+ZINIT_ICE[svn]}" else - print "${ZPLGM[col-error]}Warning${ZPLGM[col-rst]}: inconsistency #2 occurred" \ + print "${ZINIT[col-error]}Warning${ZINIT[col-rst]}: inconsistency #2 occurred" \ "- skipped storing ice-mods to" \ - "disk, please report at https://github.com/zdharma/zplugin/issues" \ - "providing the commands \`zplugin ice {...}; zplugin snippet {...}'" + "disk, please report at https://github.com/zdharma/zinit/issues" \ + "providing the commands \`zinit ice {...}; zinit snippet {...}'" fi (( retval == 1 )) && { command rmdir "$local_dir/$dirname" 2>/dev/null; return $retval; } (( retval == 2 )) && { # Run annexes' atpull hooks (the `always' after atpull-ice ones) - reply=( ${(@on)ZPLG_EXTS[(I)z-annex hook:%atpull <->]} ) + reply=( ${(@on)ZINIT_EXTS[(I)z-annex hook:%atpull <->]} ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" \%atpull done - if [[ -n ${ZPLG_ICE[ps-on-update]} ]]; then + if [[ -n ${ZINIT_ICE[ps-on-update]} ]]; then if (( !ICE_OPTS[opt_-q,--quiet] )) { - print -r "Running snippet's provided update code: ${ZPLGM[col-info]}${ZPLG_ICE[ps-on-update][1,50]}${ZPLG_ICE[ps-on-update][51]:+…}${ZPLGM[col-rst]}" + print -r "Running snippet's provided update code: ${ZINIT[col-info]}${ZINIT_ICE[ps-on-update][1,50]}${ZINIT_ICE[ps-on-update][51]:+…}${ZINIT[col-rst]}" ( builtin cd -q "$local_dir/$dirname"; - eval "${ZPLG_ICE[ps-on-update]}" + eval "${ZINIT_ICE[ps-on-update]}" ) } else { ( builtin cd -q "$local_dir/$dirname"; - eval "${ZPLG_ICE[ps-on-update]}" &> /dev/null + eval "${ZINIT_ICE[ps-on-update]}" &> /dev/null ) } fi return 0; } - [[ ${+ZPLG_ICE[make]} = 1 && ${ZPLG_ICE[make]} = "!!"* ]] && -zplg-countdown make && { local make=${ZPLG_ICE[make]}; -zplg-substitute make; command make -C "$local_dir/$dirname" ${(@s; ;)${make#\!\!}}; } + [[ ${+ZINIT_ICE[make]} = 1 && ${ZINIT_ICE[make]} = "!!"* ]] && .zinit-countdown make && { local make=${ZINIT_ICE[make]}; @zinit-substitute make; command make -C "$local_dir/$dirname" ${(@s; ;)${make#\!\!}}; } - if [[ -n "${ZPLG_ICE[mv]}" ]]; then - if [[ ${ZPLG_ICE[mv]} = *("->"|"β†’")* ]] { - local from=${ZPLG_ICE[mv]%%[[:space:]]#(->|β†’)*} to=${ZPLG_ICE[mv]##*(->|β†’)[[:space:]]#} || \ + if [[ -n "${ZINIT_ICE[mv]}" ]]; then + if [[ ${ZINIT_ICE[mv]} = *("->"|"β†’")* ]] { + local from=${ZINIT_ICE[mv]%%[[:space:]]#(->|β†’)*} to=${ZINIT_ICE[mv]##*(->|β†’)[[:space:]]#} || \ } else { - local from=${ZPLG_ICE[mv]%%[[:space:]]##*} to=${ZPLG_ICE[mv]##*[[:space:]]##} + local from=${ZINIT_ICE[mv]%%[[:space:]]##*} to=${ZINIT_ICE[mv]##*[[:space:]]##} } - -zplg-substitute from to + @zinit-substitute from to local -a afr ( () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } || return 1 afr=( ${~from}(DN) ) @@ -1108,13 +1108,13 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" ) fi - if [[ -n "${ZPLG_ICE[cp]}" ]]; then - if [[ ${ZPLG_ICE[cp]} = *("->"|"β†’")* ]] { - local from=${ZPLG_ICE[cp]%%[[:space:]]#(->|β†’)*} to=${ZPLG_ICE[cp]##*(->|β†’)[[:space:]]#} || \ + if [[ -n "${ZINIT_ICE[cp]}" ]]; then + if [[ ${ZINIT_ICE[cp]} = *("->"|"β†’")* ]] { + local from=${ZINIT_ICE[cp]%%[[:space:]]#(->|β†’)*} to=${ZINIT_ICE[cp]##*(->|β†’)[[:space:]]#} || \ } else { - local from=${ZPLG_ICE[cp]%%[[:space:]]##*} to=${ZPLG_ICE[cp]##*[[:space:]]##} + local from=${ZINIT_ICE[cp]%%[[:space:]]##*} to=${ZINIT_ICE[cp]##*[[:space:]]##} } - -zplg-substitute from to + @zinit-substitute from to local -a afr ( () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } || return 1 afr=( ${~from}(DN) ) @@ -1130,92 +1130,92 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" ) fi - [[ ${+ZPLG_ICE[make]} = 1 && ${ZPLG_ICE[make]} = ("!"[^\!]*|"!") ]] && -zplg-countdown make && { local make=${ZPLG_ICE[make]}; -zplg-substitute make; command make -C "$local_dir/$dirname" ${(@s; ;)${make#\!}}; } + [[ ${+ZINIT_ICE[make]} = 1 && ${ZINIT_ICE[make]} = ("!"[^\!]*|"!") ]] && .zinit-countdown make && { local make=${ZINIT_ICE[make]}; @zinit-substitute make; command make -C "$local_dir/$dirname" ${(@s; ;)${make#\!}}; } if [[ "$update" = "-u" ]]; then # Run annexes' atpull hooks (the before atpull-ice ones) - [[ ${ZPLG_ICE[atpull][1]} != *"!"* ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) + [[ ${ZINIT_ICE[atpull][1]} != *"!"* ]] && { + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" \!atpull done } - [[ -n "${ZPLG_ICE[atpull]}" && ${ZPLG_ICE[atpull][1]} != *"!"* ]] && -zplg-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; ((1)); } || -zplg-at-eval "${ZPLG_ICE[atpull]#!}" ${ZPLG_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} + [[ -n "${ZINIT_ICE[atpull]}" && ${ZINIT_ICE[atpull][1]} != *"!"* ]] && .zinit-countdown "atpull" && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; ((1)); } || .zinit-at-eval "${ZINIT_ICE[atpull]#!}" ${ZINIT_ICE[atclone]}; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; };} else # Run annexes' atclone hooks (the before atclone-ice ones) - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atclone <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atclone <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" \!atclone done - local atclone=${ZPLG_ICE[atclone]} - [[ -n $atclone ]] && -zplg-substitute atclone + local atclone=${ZINIT_ICE[atclone]} + [[ -n $atclone ]] && @zinit-substitute atclone - (( ${+ZPLG_ICE[atclone]} )) && -zplg-countdown "atclone" && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && eval "$atclone"; ((1)); } || eval "$atclone"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + (( ${+ZINIT_ICE[atclone]} )) && .zinit-countdown "atclone" && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && eval "$atclone"; ((1)); } || eval "$atclone"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } # Run annexes' atclone hooks (the after atclone-ice ones) - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atclone <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atclone <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" atclone done fi - [[ ${+ZPLG_ICE[make]} = 1 && ${ZPLG_ICE[make]} != "!"* ]] && -zplg-countdown make && { local make=${ZPLG_ICE[make]}; -zplg-substitute make; command make -C "$local_dir/$dirname" ${(@s; ;)make}; } + [[ ${+ZINIT_ICE[make]} = 1 && ${ZINIT_ICE[make]} != "!"* ]] && .zinit-countdown make && { local make=${ZINIT_ICE[make]}; @zinit-substitute make; command make -C "$local_dir/$dirname" ${(@s; ;)make}; } # Run annexes' atpull hooks (the after atpull-ice ones) [[ "$update" = "-u" ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atpull <->]}" ) + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atpull <->]}" ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" atpull done # Run annexes' atpull hooks (the `always' after atpull-ice ones) - reply=( ${(@on)ZPLG_EXTS[(I)z-annex hook:%atpull <->]} ) + reply=( ${(@on)ZINIT_EXTS[(I)z-annex hook:%atpull <->]} ) for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) "${arr[5]}" "snippet" "$save_url" "$id_as" "$local_dir/$dirname" \%atpull done - if [[ -n ${ZPLG_ICE[ps-on-update]} ]]; then + if [[ -n ${ZINIT_ICE[ps-on-update]} ]]; then if (( !ICE_OPTS[opt_-q,--quiet] )) { - print -r "Running snippet's provided update code: ${ZPLGM[col-info]}${ZPLG_ICE[ps-on-update][1,50]}${ZPLG_ICE[ps-on-update][51]:+…}${ZPLGM[col-rst]}" + print -r "Running snippet's provided update code: ${ZINIT[col-info]}${ZINIT_ICE[ps-on-update][1,50]}${ZINIT_ICE[ps-on-update][51]:+…}${ZINIT[col-rst]}" } - eval "${ZPLG_ICE[ps-on-update]}" + eval "${ZINIT_ICE[ps-on-update]}" fi } ((1)) ) || return $? # After additional executions like atclone'' - install completions (2 - snippets) - [[ 1 = ${+ZPLG_ICE[nocompletions]} || ${ZPLG_ICE[as]} = null ]] || -zplg-install-completions "%" "$local_dir/$dirname" 0 + [[ 1 = ${+ZINIT_ICE[nocompletions]} || ${ZINIT_ICE[as]} = null ]] || .zinit-install-completions "%" "$local_dir/$dirname" 0 return $retval } -# }}} -# FUNCTION: -zplg-get-latest-gh-r-version {{{ +# >>> +# FUNCTION: .zinit-get-latest-gh-r-version <<< # Gets version string of latest release of given Github # package. Connects to Github releases page. --zplg-get-latest-gh-r-version() { +.zinit-get-latest-gh-r-version() { setopt localoptions extendedglob warncreateglobal - -zplg-any-to-user-plugin "$1" "$2" + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" local plugin="${reply[-1]}" local url="https://github.com/$user/$plugin/releases/latest" local -a list - list=( ${(@f)"$( { -zplg-download-file-stdout $url || -zplg-download-file-stdout $url 1; } 2>/dev/null | \ + list=( ${(@f)"$( { .zinit-download-file-stdout $url || .zinit-download-file-stdout $url 1; } 2>/dev/null | \ command grep -o 'href=./'$user'/'$plugin'/releases/download/[^"]\+')"} ) list=( "${(uOn)list[@]/(#b)href=?(\/[^\/]##)(#c4,4)\/([^\/]##)*/${match[2]}}" ) REPLY="${list[1]}" } -# }}} -# FUNCTION: zpextract {{{ +# >>> +# FUNCTION: ziextract <<< # If the file is an archive, it is extracted by this function. # Next stage is scanning of files with the common utility `file', # to detect executables. They are given +x mode. There are also @@ -1223,37 +1223,37 @@ builtin source ${ZPLGM[BIN_DIR]}"/zplugin-side.zsh" # # $1 - url # $2 - file -zpextract() { +ziextract() { emulate -LR zsh setopt extendedglob warncreateglobal typesetsilent noshortloops local -a opt_move opt_norm zparseopts -D -E -move=opt_move -norm=opt_norm || \ - { print -P -r -- "%F{160}Incorrect options given to \`zpextract' (available are: %F{221}--move%F{160})%f"; return 1; } + { print -P -r -- "%F{160}Incorrect options given to \`ziextract' (available are: %F{221}--move%F{160})%f"; return 1; } local file="$1" ext="$2" integer move=${${${(M)${#opt_move}:#0}:+0}:-1} norm=${${${(M)${#opt_norm}:#0}:+0}:-1} if [[ ! -e $file ]] { - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]}" \ - "${ZPLGM[col-error]}ERROR:${ZPLGM[col-msg2]}" \ - "the file \`${ZPLGM[col-obj]}$file${ZPLGM[col-msg2]}'" \ + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]}" \ + "${ZINIT[col-error]}ERROR:${ZINIT[col-msg2]}" \ + "the file \`${ZINIT[col-obj]}$file${ZINIT[col-msg2]}'" \ "doesn't exist, aborting the extraction." return 1 } command mkdir -p ._backup command rm -rf ._backup/*(DN) - command mv -f *~(._zplugin*|.zplugin_lstupd|._backup|.git|$file)(DN) ._backup 2>/dev/null + command mv -f *~(._zinit*|.zinit_lastupd|._backup|.git|$file)(DN) ._backup 2>/dev/null - -zplg-extract-wrapper() { + .zinit-extract-wrapper() { local file="$1" fun="$2" retval (( !ICE_OPTS[opt_-q,--quiet] )) && \ - print "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-msg1]} Unpacking the files from:" \ - "\`${ZPLGM[col-obj]}$file${ZPLGM[col-msg1]}'...${ZPLGM[col-rst]}" + print "${ZINIT[col-pre]}ziextract:${ZINIT[col-msg1]} Unpacking the files from:" \ + "\`${ZINIT[col-obj]}$file${ZINIT[col-msg1]}'...${ZINIT[col-rst]}" $fun; retval=$? (( retval == 0 )) && { local -a files - files=( *~(._zplugin*|.zplugin_lstupd|._backup|.git|$file)(DN) ) + files=( *~(._zinit*|.zinit_lastupd|._backup|.git|$file)(DN) ) (( ${#files} && !norm )) && command rm -f "$file" } return $retval @@ -1261,40 +1261,40 @@ zpextract() { case "${${ext:+.$ext}:-$file}" in (*.zip) - -zplg-extract() { command unzip -o "$file"; } + :zinit-extract() { command unzip -o "$file"; } ;; (*.rar) - -zplg-extract() { command unrar x "$file"; } + :zinit-extract() { command unrar x "$file"; } ;; (*.tar.bz2|*.tbz2) - -zplg-extract() { command bzip2 -dc "$file" | command tar -xf -; } + :zinit-extract() { command bzip2 -dc "$file" | command tar -xf -; } ;; (*.tar.gz|*.tgz) - -zplg-extract() { command gzip -dc "$file" | command tar -xf -; } + :zinit-extract() { command gzip -dc "$file" | command tar -xf -; } ;; (*.tar.xz|*.txz) - -zplg-extract() { command xz -dc "$file" | command tar -xf -; } + :zinit-extract() { command xz -dc "$file" | command tar -xf -; } ;; (*.tar.7z|*.t7z) - -zplg-extract() { command 7z x -so "$file" | command tar -xf -; } + :zinit-extract() { command 7z x -so "$file" | command tar -xf -; } ;; (*.tar) - -zplg-extract() { command tar -xf "$file"; } + :zinit-extract() { command tar -xf "$file"; } ;; (*.gz) - -zplg-extract() { command gunzip "$file"; } + :zinit-extract() { command gunzip "$file"; } ;; (*.dmg) - -zplg-extract() { + :zinit-extract() { local prog for prog ( hdiutil cp ) { if ! command -v $prog &>/dev/null; then - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]}" \ - "${ZPLGM[col-error]}ERROR:${ZPLGM[col-msg2]}" \ - "no \`${ZPLGM[col-obj]}$prog${ZPLGM[col-msg2]}'" \ + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]}" \ + "${ZINIT[col-error]}ERROR:${ZINIT[col-msg2]}" \ + "no \`${ZINIT[col-obj]}$prog${ZINIT[col-msg2]}'" \ "command found – it is required to extract a" \ - "${ZPLGM[col-obj]}dmg${ZPLGM[col-msg2]} image." \ - ${ZPLGM[col-rst]} + "${ZINIT[col-obj]}dmg${ZINIT[col-msg2]} image." \ + ${ZINIT[col-rst]} return 1 fi } @@ -1308,48 +1308,48 @@ zpextract() { command hdiutil detach $attached_vol (( retval )) && { - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]}" \ - "${ZPLGM[col-error]}Warning:${ZPLGM[col-msg1]}" \ + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]}" \ + "${ZINIT[col-error]}Warning:${ZINIT[col-msg1]}" \ "problem occurred when attempted to copy the files" \ "from the mounted image: " \ - "\`${ZPLGM[col-obj]}$file${ZPLGM[col-msg1]}'." + "\`${ZINIT[col-obj]}$file${ZINIT[col-msg1]}'." } return $retval } ;; esac - if [[ $(typeset -f + -- -zplg-extract) == "-zplg-extract" ]] { - -zplg-extract-wrapper "$file" -zplg-extract || { + if [[ $(typeset -f + -- :zinit-extract) == ":zinit-extract" ]] { + .zinit-extract-wrapper "$file" :zinit-extract || { local -a bfiles bfiles=( ._backup/*(DN) ) if (( ${#bfiles} )) { - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]}" \ - "${ZPLGM[col-error]}WARNING:${ZPLGM[col-msg1]}" \ + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]}" \ + "${ZINIT[col-error]}WARNING:${ZINIT[col-msg1]}" \ "extraction of archive had problems, restoring previous" \ - "version of the plugin/snippet.${ZPLGM[col-rst]}" + "version of the plugin/snippet.${ZINIT[col-rst]}" command mv ._backup/*(DN) . 2>/dev/null } else { - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]}" \ - "${ZPLGM[col-error]}WARNING:${ZPLGM[col-msg1]}" \ + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]}" \ + "${ZINIT[col-error]}WARNING:${ZINIT[col-msg1]}" \ "extraction of the archive" \ - "\`${ZPLGM[col-obj]}$file${ZPLGM[col-msg1]}' had problems." \ - ${ZPLGM[col-rst]} + "\`${ZINIT[col-obj]}$file${ZINIT[col-msg1]}' had problems." \ + ${ZINIT[col-rst]} } return 1 } - unfunction -- -zplg-extract + unfunction -- :zinit-extract } else { - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]}" \ - "${ZPLGM[col-error]}WARNING: ${ZPLGM[col-msg1]}didn't recognize the archive" \ - "type of \`${ZPLGM[col-obj]}$file${ZPLGM[col-msg1]}'" \ - "${ext:+${ZPLGM[col-obj2]}/ $ext${ZPLGM[col-msg1]} }"\ -"(no extraction has been done).${ZPLGM[col-rst]}" + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]}" \ + "${ZINIT[col-error]}WARNING: ${ZINIT[col-msg1]}didn't recognize the archive" \ + "type of \`${ZINIT[col-obj]}$file${ZINIT[col-msg1]}'" \ + "${ext:+${ZINIT[col-obj2]}/ $ext${ZINIT[col-msg1]} }"\ +"(no extraction has been done).${ZINIT[col-rst]}" } - unfunction -- -zplg-extract-wrapper + unfunction -- .zinit-extract-wrapper local -a execs - execs=( **/*~(._zplugin(|/*)|.git(|/*)|._backup(|/*))(DN-.) ) + execs=( **/*~(._zinit(|/*)|.git(|/*)|._backup(|/*))(DN-.) ) [[ ${#execs} -gt 0 && -n $execs ]] && { execs=( ${(@f)"$( file ${execs[@]} )"} ) execs=( "${(M)execs[@]:#[^:]##:*executable*}" ) @@ -1360,22 +1360,22 @@ zpextract() { command chmod a+x "${execs[@]}" (( !ICE_OPTS[opt_-q,--quiet] )) && \ if (( ${#execs} == 1 )); then - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]}" \ + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]}" \ "Successfully extracted and assigned +x chmod to the file:" \ - "\`${ZPLGM[col-obj]}${execs[1]}${ZPLGM[col-rst]}'." + "\`${ZINIT[col-obj]}${execs[1]}${ZINIT[col-rst]}'." else - local sep="${ZPLGM[col-rst]},${ZPLGM[col-obj]} " - print -r -- "${ZPLGM[col-pre]}zpextract:${ZPLGM[col-rst]} Successfully" \ + local sep="${ZINIT[col-rst]},${ZINIT[col-obj]} " + print -r -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-rst]} Successfully" \ "extracted and marked executable the appropriate files" \ - "(${ZPLGM[col-obj]}${(pj:$sep:)${execs[@]:t}}${ZPLGM[col-rst]}) contained" \ - "in \`${ZPLGM[col-file]}$file${ZPLGM[col-rst]}'." + "(${ZINIT[col-obj]}${(pj:$sep:)${execs[@]:t}}${ZINIT[col-rst]}) contained" \ + "in \`${ZINIT[col-file]}$file${ZINIT[col-rst]}'." fi } (( move )) && { # TODO: mkdir .tmp231ABC - command mv -f *~(._zplugin|.git|._backup)(DN[1]) .tmp231ABC - command mv -f **/*~(*/*/*|^*/*|._zplugin(|/*)|.git(|/*)|._backup(|/*))(DN) . + command mv -f *~(._zinit|.git|._backup)(DN[1]) .tmp231ABC + command mv -f **/*~(*/*/*|^*/*|._zinit(|/*)|.git(|/*)|._backup(|/*))(DN) . command rmdir .tmp231ABC REPLY="${${execs[1]:h}:h}/${execs[1]:t}" } || { @@ -1383,15 +1383,18 @@ zpextract() { } return 0 } -# }}} -# FUNCTION: -zplg-at-eval {{{ --zplg-at-eval() { +# >>> +# FUNCTION: zpextract <<< +zpextract() { ziextract "$@"; } +# >>> +# FUNCTION: .zinit-at-eval <<< +.zinit-at-eval() { local atclone="$2" atpull="$1" integer retval - -zplg-substitute atclone atpull + @zinit-substitute atclone atpull [[ $atpull = "%atclone" ]] && { eval "$atclone"; retval=$?; } || { eval "$atpull"; retval=$?; } return $retval } -# }}} +# >>> -# vim:ft=zsh:sw=4:sts=4:et +# vim:ft=zsh:sw=4:sts=4:et:foldmarker=<<<,>>> diff --git a/zplugin-side.zsh b/zinit-side.zsh similarity index 69% rename from zplugin-side.zsh rename to zinit-side.zsh index 84dd1758..eb9e2b12 100644 --- a/zplugin-side.zsh +++ b/zinit-side.zsh @@ -1,12 +1,12 @@ # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # Copyright (c) 2019 Sebastian Gniazdowski and contributors -# FUNCTION: -zplg-shands-exp {{{ +# FUNCTION: .zinit-shands-exp <<< # Does expansion of currently little unstandarized # shorthands like "%SNIPPETS", "%HOME", "OMZ::", "PZT::". --zplg-shands-exp() { +.zinit-shands-exp() { REPLY="$1$2" - REPLY="${${${REPLY/\%HOME/$HOME}/\%SNIPPETS/${ZPLGM[SNIPPETS_DIR]}}#%}" + REPLY="${${${REPLY/\%HOME/$HOME}/\%SNIPPETS/${ZINIT[SNIPPETS_DIR]}}#%}" #REPLY="${REPLY/OMZ::/https--github.com--robbyrussell--oh-my-zsh--trunk--}" #REPLY="${REPLY/\/OMZ//https--github.com--robbyrussell--oh-my-zsh--trunk}" #REPLY="${REPLY/PZT::/https--github.com--sorin-ionescu--prezto--trunk--}" @@ -15,28 +15,28 @@ # Testable [[ "$REPLY" != "$1$2" ]] } -# }}} -# FUNCTION: -zplg-exists-physically {{{ +# >>> +# FUNCTION: .zinit-exists-physically <<< # Checks if directory of given plugin exists in PLUGIN_DIR. # # Testable. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-exists-physically() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-exists-physically() { + .zinit-any-to-user-plugin "$1" "$2" if [[ "${reply[-2]}" = "%" ]]; then # Shorthands, little unstandarized - -zplg-shands-exp "$1" "$2" && { + .zinit-shands-exp "$1" "$2" && { [[ -d "$REPLY" ]] && return 0 || return 1 } || { [[ -d "${reply[-1]}" ]] && return 0 || return 1 } else - [[ -d "${ZPLGM[PLUGINS_DIR]}/${reply[-2]:+${reply[-2]}---}${reply[-1]//\//---}" ]] && return 0 || return 1 + [[ -d "${ZINIT[PLUGINS_DIR]}/${reply[-2]:+${reply[-2]}---}${reply[-1]//\//---}" ]] && return 0 || return 1 fi -} # }}} -# FUNCTION: -zplg-exists-physically-message {{{ +} # >>> +# FUNCTION: .zinit-exists-physically-message <<< # Checks if directory of given plugin exists in PLUGIN_DIR, # and outputs error message if it doesn't. # @@ -44,56 +44,56 @@ # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-exists-physically-message() { - if ! -zplg-exists-physically "$1" "$2"; then - -zplg-any-colorify-as-uspl2 "$1" "$2" +.zinit-exists-physically-message() { + if ! .zinit-exists-physically "$1" "$2"; then + .zinit-any-colorify-as-uspl2 "$1" "$2" local spec="$REPLY" - -zplg-shands-exp "$1" "$2" && REPLY="${REPLY/$HOME/~}" + .zinit-shands-exp "$1" "$2" && REPLY="${REPLY/$HOME/~}" - print -r -- "${ZPLGM[col-error]}No such (plugin or snippet) directory${ZPLGM[col-rst]}: $spec" + print -r -- "${ZINIT[col-error]}No such (plugin or snippet) directory${ZINIT[col-rst]}: $spec" [[ "$REPLY" != "$1$2" ]] && print -r -- "(expands to: $REPLY)" return 1 fi return 0 -} # }}} -# FUNCTION: -zplg-plgdir {{{ --zplg-get-plg-dir() { +} # >>> +# FUNCTION: .zinit-plgdir <<< +.zinit-get-plg-dir() { # There are plugins having ".plugin.zsh" # in ${plugin} directory name, also some # have ".zsh" there - local dname="${ZPLGM[alias-map-${user:+${user}/}$plugin]}" + local dname="${ZINIT[alias-map-${user:+${user}/}$plugin]}" local pdir="${${${${plugin:t}%.plugin.zsh}%.zsh}%.git}" [[ -z "$dname" ]] && { [[ "$user" = "%" ]] && dname="$plugin" || \ - dname="${ZPLGM[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" + dname="${ZINIT[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}" } reply=( "$dname" "$pdir" ) return 0 } -# }}} -# FUNCTION: -zplg-first {{{ +# >>> +# FUNCTION: .zinit-first <<< # Finds the main file of plugin. There are multiple file name # formats, they are ordered in order starting from more correct -# ones, and matched. -zplg-load-plugin() has similar code parts -# and doesn't call -zplg-first() – for performance. Obscure matching -# is done in -zplg-find-other-matches, here and in -zplg-load(). +# ones, and matched. .zinit-load-plugin() has similar code parts +# and doesn't call .zinit-first() – for performance. Obscure matching +# is done in .zinit-find-other-matches, here and in .zinit-load(). # Obscure = non-standard main-file naming convention. # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) --zplg-first() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-first() { + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" - -zplg-get-plg-dir "$user" "$plugin" + .zinit-get-plg-dir "$user" "$plugin" local dname="${reply[-2]}" # Look for file to compile. First look for the most common one # (optimization) then for other possibilities if [[ ! -e "$dname/${reply[-1]}.plugin.zsh" ]]; then - -zplg-find-other-matches "$dname" "${reply[-1]}" + .zinit-find-other-matches "$dname" "${reply[-1]}" else reply=( "$dname/${reply[-1]}.plugin.zsh" ) fi @@ -106,32 +106,32 @@ # Take first entry (ksharrays resilience) reply=( "$dname" "${reply[-${#reply}]}" ) return 0 -} # }}} -# FUNCTION: -zplg-any-colorify-as-uspl2 {{{ +} # >>> +# FUNCTION: .zinit-any-colorify-as-uspl2 <<< # Returns ANSI-colorified "user/plugin" string, from any supported # plugin spec (user---plugin, user/plugin, user plugin, plugin). # # $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) # $2 - plugin (only when $1 - i.e. user - given) # $REPLY = ANSI-colorified "user/plugin" string --zplg-any-colorify-as-uspl2() { - -zplg-any-to-user-plugin "$1" "$2" +.zinit-any-colorify-as-uspl2() { + .zinit-any-to-user-plugin "$1" "$2" local user="${reply[-2]}" plugin="${reply[-1]}" [[ "$user" = "%" ]] && { - plugin="${plugin/${ZPLGM[SNIPPETS_DIR]}/SNIPPETS}" + plugin="${plugin/${ZINIT[SNIPPETS_DIR]}/SNIPPETS}" plugin="${plugin/https--github.com--robbyrussell--oh-my-zsh--trunk--/OMZ::}" plugin="${plugin/https--github.com--robbyrussell--oh-my-zsh--trunk/OMZ}" plugin="${plugin/https--github.com--sorin-ionescu--prezto--trunk--/PZT::}" plugin="${plugin/https--github.com--sorin-ionescu--prezto--trunk/PZT}" plugin="${plugin/$HOME/HOME}" - REPLY="${ZPLGM[col-uname]}%${ZPLGM[col-rst]}${ZPLGM[col-pname]}${plugin}${ZPLGM[col-rst]}" - } || REPLY="${user:+${ZPLGM[col-uname]}${user}${ZPLGM[col-rst]}/}${ZPLGM[col-pname]}${plugin}${ZPLGM[col-rst]}" -} # }}} -# FUNCTION: -zplg-two-paths {{{ + REPLY="${ZINIT[col-uname]}%${ZINIT[col-rst]}${ZINIT[col-pname]}${plugin}${ZINIT[col-rst]}" + } || REPLY="${user:+${ZINIT[col-uname]}${user}${ZINIT[col-rst]}/}${ZINIT[col-pname]}${plugin}${ZINIT[col-rst]}" +} # >>> +# FUNCTION: .zinit-two-paths <<< # Obtains a snippet URL without specification if it is an SVN URL (points to # directory) or regular URL (points to file), returns 2 possible paths for # further examination --zplg-two-paths() { +.zinit-two-paths() { setopt localoptions extendedglob nokshglob noksharrays noshwordsplit local url="$1" url1 url2 local_dirA svn_dirA local_dirB dirnameA dirnameB local -a fileB_there @@ -140,48 +140,49 @@ url="${${url#"${url%%[! $'\t']*}"}%/}" url1="$url" url2="$url" - #url1[1,5]="${ZPLG_1MAP[${url[1,5]}]:-${url[1,5]}}" # svn - #url2[1,5]="${ZPLG_2MAP[${url[1,5]}]:-${url[1,5]}}" # normal + #url1[1,5]="${ZINIT_1MAP[${url[1,5]}]:-${url[1,5]}}" # svn + #url2[1,5]="${ZINIT_2MAP[${url[1,5]}]:-${url[1,5]}}" # normal dirnameA="${${url1%%\?*}:t}" local_dirA="${${${url1%%\?*}:h}/:\/\//--}" [[ "$local_dirA" = "." ]] && local_dirA="" || local_dirA="${${${${${local_dirA#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}" - local_dirA="${ZPLGM[SNIPPETS_DIR]}${local_dirA:+/$local_dirA}" + local_dirA="${ZINIT[SNIPPETS_DIR]}${local_dirA:+/$local_dirA}" [[ -d "$local_dirA/$dirnameA/.svn" ]] && svn_dirA=".svn" dirnameB="${${url2%%\?*}:t}" local_dirB="${${${url2%%\?*}:h}/:\/\//--}" [[ "$local_dirB" = "." ]] && local_dirB="" || local_dirB="${${${${${local_dirB#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}" - local_dirB="${ZPLGM[SNIPPETS_DIR]}${local_dirB:+/$local_dirB}" + local_dirB="${ZINIT[SNIPPETS_DIR]}${local_dirB:+/$local_dirB}" fileB_there=( "$local_dirB/$dirnameB"/*~*.zwc(.DOnN[1]) ) reply=( "$local_dirA/$dirnameA" "$svn_dirA" "$local_dirB/$dirnameB" "${fileB_there[1]##$local_dirB/$dirnameB/#}" ) } -# }}} -# FUNCTION: -zplg-compute-ice {{{ -# Computes ZPLG_ICE array (default, it can be specified via $3) from a) input -# ZPLG_ICE, b) static ice, c) saved ice, taking priorities into account. Also +# >>> +# FUNCTION: .zinit-compute-ice <<< +# Computes ZINIT_ICE array (default, it can be specified via $3) from a) input +# ZINIT_ICE, b) static ice, c) saved ice, taking priorities into account. Also # returns path to snippet directory and optional name of snippet file (only -# valid if ZPLG_ICE[svn] is not set). +# valid if ZINIT_ICE[svn] is not set). # -# Can also pack resulting ices into ZPLG_SICE (see $2). +# Can also pack resulting ices into ZINIT_SICE (see $2). # # $1 - URL (also plugin-spec) -# $2 - "pack" or "nopack" or "pack-nf" - packing means ZPLG_ICE +# $2 - "pack" or "nopack" or "pack-nf" - packing means ZINIT_ICE # wins with static ice; "pack-nf" means that disk-ices will # be ignored (no-file?) -# $3 - name of output associative array, "ZPLG_ICE" is the default +# $3 - name of output associative array, "ZINIT_ICE" is the default # $4 - name of output string parameter, to hold path to directory ("local_dir") # $5 - name of output string parameter, to hold filename ("filename") # $6 - name of output string parameter, to hold is-snippet 0/1-bool ("is_snippet") --zplg-compute-ice() { - setopt localoptions extendedglob nokshglob noksharrays +.zinit-compute-ice() { + emulate -LR zsh + setopt extendedglob typesetsilent warncreateglobal noshortloops local __URL="${1%/}" __pack="$2" __is_snippet=0 - local __var_name1="${3:-ZPLG_ICE}" __var_name2="${4:-local_dir}" \ + local __var_name1="${3:-ZINIT_ICE}" __var_name2="${4:-local_dir}" \ __var_name3="${5:-filename}" __var_name4="${6:-is_snippet}" - # Copy from -zplg-recall + # Copy from .zinit-recall local -a ice_order nval_ices ice_order=( svn proto from teleid bindmap cloneopts id-as depth if wait load @@ -194,7 +195,7 @@ subscribe param # Include all additional ices – after # stripping them from the possible: '' - ${(@us.|.)${ZPLG_EXTS[ice-mods]//\'\'/}} + ${(@us.|.)${ZINIT_EXTS[ice-mods]//\'\'/}} ) nval_ices=( blockf silent lucid trackbinds cloneonly nocd run-atpull @@ -204,7 +205,7 @@ # Include only those additional ices, # don't have the '' in their name, i.e. # aren't designed to hold value - ${(@)${(@s.|.)ZPLG_EXTS[ice-mods]}:#*\'\'*} + ${(@)${(@s.|.)ZINIT_EXTS[ice-mods]}:#*\'\'*} # Must be last svn @@ -214,26 +215,26 @@ __URL="${${__URL#"${__URL%%[! $'\t']*}"}%/}" # Snippet? - -zplg-two-paths "$__URL" + .zinit-two-paths "$__URL" local __s_path="${reply[-4]}" __s_svn="${reply[-3]}" ___path="${reply[-2]}" __filename="${reply[-1]}" __local_dir if [[ -d "$__s_path" || -d "$___path" ]]; then __is_snippet=1 else # Plugin - -zplg-shands-exp "$__URL" && __URL="$REPLY" - -zplg-any-to-user-plugin "$__URL" "" + .zinit-shands-exp "$__URL" && __URL="$REPLY" + .zinit-any-to-user-plugin "$__URL" "" local __user="${reply[-2]}" __plugin="${reply[-1]}" __s_path="" __filename="" - [[ "$__user" = "%" ]] && ___path="$__plugin" || ___path="${ZPLGM[PLUGINS_DIR]}/${__user:+${__user}---}${__plugin//\//---}" - -zplg-exists-physically-message "$__user" "$__plugin" || return 1 + [[ "$__user" = "%" ]] && ___path="$__plugin" || ___path="${ZINIT[PLUGINS_DIR]}/${__user:+${__user}---}${__plugin//\//---}" + .zinit-exists-physically-message "$__user" "$__plugin" || return 1 fi - [[ $__pack = pack* ]] && (( ${#ZPLG_ICE} > 0 )) && \ - -zplg-pack-ice "${__user-$__URL}" "$__plugin" + [[ $__pack = pack* ]] && (( ${#ZINIT_ICE} > 0 )) && \ + .zinit-pack-ice "${__user-$__URL}" "$__plugin" local -A __sice local -a __tmp - __tmp=( "${(z@)ZPLG_SICE[$__user${${__user:#(%|/)*}:+/}$__plugin]}" ) + __tmp=( "${(z@)ZINIT_SICE[$__user${${__user:#(%|/)*}:+/}$__plugin]}" ) (( ${#__tmp[@]} > 1 && ${#__tmp[@]} % 2 == 0 )) && __sice=( "${(Q)__tmp[@]}" ) if [[ "${+__sice[svn]}" = "1" || -n "$__s_svn" ]]; then @@ -242,7 +243,7 @@ print -r -- "(\`svn' can be used only with snippets)" return 1 elif (( !__is_snippet )); then - print -r -- "Undefined behavior #1 occurred, please report at https://github.com/zdharma/zplugin/issues" + print -r -- "Undefined behavior #1 occurred, please report at https://github.com/zdharma/zinit/issues" return 1 fi if [[ -e "$__s_path" && -n "$__s_svn" ]]; then @@ -263,36 +264,50 @@ fi fi - local __zplugin_path="$__local_dir/._zplugin" + local __zinit_path="$__local_dir/._zinit" + + # Zplugin -> Zinit rename upgrade code + if [[ ! -d $__zinit_path && -d $__local_dir/._zplugin ]]; then + ( + print -Pr -- "${ZINIT[col-pre]}UPGRADING THE DIRECTORY STRUCTURE" \ + "FOR THE ZPLUGIN -> ZINIT RENAME…%f" + builtin cd -q ${ZINIT[PLUGINS_DIR]} || return 1 + autoload -Uz zmv + ( zmv -W '**/._zplugin' '**/._zinit' ) &>/dev/null + builtin cd -q ${ZINIT[SNIPPETS_DIR]} || return 1 + ( zmv -W '**/._zplugin' '**/._zinit' ) &>/dev/null + print -Pr -- "${ZINIT[col-obj]}THE UPGRADE SUCCEDED!%f" + ) || print -Pr -- "${ZINIT[col-error]}THE UPGRADE FAILED!%f" + fi # Read disk-Ice local -A __mdata local __key { for __key in mode url is_release ${ice_order[@]}; do - [[ -f "$__zplugin_path/$__key" ]] && __mdata[$__key]="$(<$__zplugin_path/$__key)" + [[ -f "$__zinit_path/$__key" ]] && __mdata[$__key]="$(<$__zinit_path/$__key)" done [[ "${__mdata[mode]}" = "1" ]] && __mdata[svn]="" } 2>/dev/null # Handle flag-Ices; svn must be last for __key in ${ice_order[@]}; do - (( 0 == ${+ZPLG_ICE[no$__key]} && 0 == ${+__sice[no$__key]} )) && continue + (( 0 == ${+ZINIT_ICE[no$__key]} && 0 == ${+__sice[no$__key]} )) && continue # "If there is such ice currently, and there's no no* ice given, # and there's the no* ice in the static ice" – skip, don't unset. # With conjunction with the previous line this has the proper # meaning: uset if at least in one – current or static – ice # there's the no* ice, but not if it's only in the static ice # (unless there's on such ice "anyway"). - (( 1 == ${+ZPLG_ICE[$__key]} && 0 == ${+ZPLG_ICE[no$__key]} && \ + (( 1 == ${+ZINIT_ICE[$__key]} && 0 == ${+ZINIT_ICE[no$__key]} && \ 1 == ${+__sice[no$__key]} )) && continue if [[ "$__key" = "svn" ]]; then - command print -r -- "0" >! "$__zplugin_path/mode" + command print -r -- "0" >! "$__zinit_path/mode" __mdata[mode]=0 else - command rm -f -- "$__zplugin_path/$__key" + command rm -f -- "$__zinit_path/$__key" fi - unset "__mdata[$__key]" "__sice[$__key]" "ZPLG_ICE[$__key]" + unset "__mdata[$__key]" "__sice[$__key]" "ZINIT_ICE[$__key]" done # Final decision, static ice vs. saved ice @@ -313,8 +328,8 @@ return 0 } -# }}} -# FUNCTION: -zplg-store-ices {{{ +# >>> +# FUNCTION: .zinit-store-ices <<< # Saves ice mods in given hash onto disk. # # $1 - directory where to create / delete files @@ -323,12 +338,12 @@ # $4 - additional keys of hash to store, empty-meaningful ices, space separated # $5 – the URL, if applicable # $6 – the mode (1 - svn, 0 - single file), if applicable --zplg-store-ices() { +.zinit-store-ices() { local __pfx="$1" __ice_var="$2" \ __add_ices="$3" __add_ices2="$4" \ url="$5" mode="$6" - # Copy from -zplg-recall + # Copy from .zinit-recall local -a ice_order nval_ices ice_order=( svn proto from teleid bindmap cloneopts id-as depth if wait load @@ -341,7 +356,7 @@ subscribe param # Include all additional ices – after # stripping them from the possible: '' - ${(@s.|.)${ZPLG_EXTS[ice-mods]//\'\'/}} + ${(@s.|.)${ZINIT_EXTS[ice-mods]//\'\'/}} ) nval_ices=( blockf silent lucid trackbinds cloneonly nocd run-atpull @@ -351,7 +366,7 @@ # Include only those additional ices, # don't have the '' in their name, i.e. # aren't designed to hold value - ${(@)${(@s.|.)ZPLG_EXTS[ice-mods]}:#*\'\'*} + ${(@)${(@s.|.)ZINIT_EXTS[ice-mods]}:#*\'\'*} # Must be last svn @@ -381,27 +396,27 @@ [[ -n "${(P)__key}" ]] && print -r -- "${(P)__key}" >! "$__pfx"/"$__key" done } -# }}} -# FUNCTION: -zplg-countdown {{{ +# >>> +# FUNCTION: .zinit-countdown <<< # Displays a countdown 5...4... etc. and returns 0 if it # sucessfully reaches 0, or 1 if Ctrl-C will be pressed. --zplg-countdown() { - (( !${+ZPLG_ICE[countdown]} )) && return 0 +.zinit-countdown() { + (( !${+ZINIT_ICE[countdown]} )) && return 0 emulate -L zsh - trap "print \"${ZPLGM[col-pname]}ABORTING, the ice not ran${ZPLGM[col-rst]}\"; return 1" INT + trap "print \"${ZINIT[col-pname]}ABORTING, the ice not ran${ZINIT[col-rst]}\"; return 1" INT local count=5 tpe="$1" ice - ice="${ZPLG_ICE[$tpe]}" - [[ $tpe = "atpull" && $ice = "%atclone" ]] && ice="${ZPLG_ICE[atclone]}" + ice="${ZINIT_ICE[$tpe]}" + [[ $tpe = "atpull" && $ice = "%atclone" ]] && ice="${ZINIT_ICE[atclone]}" ice="$tpe:$ice" - print -nr "${ZPLGM[col-pname]}Running ${ZPLGM[col-bold]}${ZPLGM[col-uname]}$ice${ZPLGM[col-rst]}${ZPLGM[col-pname]} ice in...${ZPLGM[col-rst]} " + print -nr "${ZINIT[col-pname]}Running ${ZINIT[col-bold]}${ZINIT[col-uname]}$ice${ZINIT[col-rst]}${ZINIT[col-pname]} ice in...${ZINIT[col-rst]} " while (( -- count + 1 )) { - print -nr -- "${ZPLGM[col-bold]}${ZPLGM[col-error]}"$(( count + 1 ))..."${ZPLGM[col-rst]}" + print -nr -- "${ZINIT[col-bold]}${ZINIT[col-error]}"$(( count + 1 ))..."${ZINIT[col-rst]}" sleep 1 } - print -r -- "${ZPLGM[col-bold]}${ZPLGM[col-error]}0 ...${ZPLGM[col-rst]}" + print -r -- "${ZINIT[col-bold]}${ZINIT[col-error]}0 ...${ZINIT[col-rst]}" return 0 } -# }}} +# >>> -# vim:ft=zsh:sw=4:sts=4:et +# vim:ft=zsh:sw=4:sts=4:et:foldmarker=<<<,>>> diff --git a/zinit.zsh b/zinit.zsh new file mode 100644 index 00000000..678da199 --- /dev/null +++ b/zinit.zsh @@ -0,0 +1,2443 @@ +# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# Copyright (c) 2019 Sebastian Gniazdowski and contributors + +# +# Main state variables +# + +typeset -gaH ZINIT_REGISTERED_PLUGINS ZINIT_TASKS ZINIT_RUN +typeset -ga zsh_loaded_plugins +ZINIT_TASKS=( "" ) +# Snippets loaded, url -> file name +typeset -gAH ZINIT ZINIT_REGISTERED_STATES ZINIT_SNIPPETS ZINIT_REPORTS ZINIT_ICES ZINIT_SICE ZINIT_CUR_BIND_MAP ZINIT_EXTS +typeset -gaH ZINIT_COMPDEF_REPLAY + +# Compatibility with pre-rename project (Zinit) +typeset -gAH ZPLGM +print -rl "${(kvq)ZPLGM[@]}" +ZINIT=( "${(kv)ZPLGM[@]}" ) +unset ZPLGM + +# +# Common needed values +# + +[[ ! -e ${ZINIT[BIN_DIR]}/zinit.zsh ]] && ZINIT[BIN_DIR]= + +ZINIT[ZERO]="$0" +[[ ! -o functionargzero || ${ZINIT[ZERO]/\//} = ${ZINIT[ZERO]} ]] && ZINIT[ZERO]="${(%):-%N}" + +[[ -z ${ZINIT[BIN_DIR]} ]] && ZINIT[BIN_DIR]="${ZINIT[ZERO]:h}" +[[ ${ZINIT[BIN_DIR]} = \~* ]] && ZINIT[BIN_DIR]=${~ZINIT[BIN_DIR]} + +# Make ZINIT[BIN_DIR] path absolute +ZINIT[BIN_DIR]="${${(M)ZINIT[BIN_DIR]:#/*}:-$PWD/${ZINIT[BIN_DIR]}}" + +# Final test of ZINIT[BIN_DIR] +if [[ ! -e ${ZINIT[BIN_DIR]}/zinit.zsh ]]; then + print "Could not establish ZINIT[BIN_DIR] hash field. It should point where Zinit's git repository is." + return 1 +fi + +# User can override ZINIT[HOME_DIR] +if [[ -z ${ZINIT[HOME_DIR]} ]]; then + # Ignore ZDOTDIR if user manually put Zinit to $HOME + if [[ -d $HOME/.zinit ]]; then + ZINIT[HOME_DIR]="$HOME/.zinit" + elif [[ -d $HOME/.zplugin ]]; then + ZINIT[HOME_DIR]="$HOME/.zplugin" + elif [[ -d ${ZDOTDIR:-HOME}/.zplugin ]]; then + ZINIT[HOME_DIR]="${ZDOTDIR:-$HOME}/.zplugin" + else + ZINIT[HOME_DIR]="${ZDOTDIR:-$HOME}/.zinit" + fi +fi + +# Can be customized +: ${ZINIT[PLUGINS_DIR]:=${ZINIT[HOME_DIR]}/plugins} +: ${ZINIT[COMPLETIONS_DIR]:=${ZINIT[HOME_DIR]}/completions} +: ${ZINIT[SNIPPETS_DIR]:=${ZINIT[HOME_DIR]}/snippets} +: ${ZINIT[SERVICES_DIR]:=${ZINIT[HOME_DIR]}/services} +typeset -g ZPFX +: ${ZPFX:=${ZINIT[HOME_DIR]}/polaris} + +ZINIT[PLUGINS_DIR]=${~ZINIT[PLUGINS_DIR]} ZINIT[COMPLETIONS_DIR]=${~ZINIT[COMPLETIONS_DIR]} +ZINIT[SNIPPETS_DIR]=${~ZINIT[SNIPPETS_DIR]} ZINIT[SERVICES_DIR]=${~ZINIT[SERVICES_DIR]} +export ZPFX=${~ZPFX} ZSH_CACHE_DIR="${ZSH_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache/zinit}}" +[[ -n ${path[(re)$ZPFX/bin]} ]] || path=( "$ZPFX/bin" ${path[@]} ) + +[[ ! -d $ZSH_CACHE_DIR ]] && command mkdir -p "$ZSH_CACHE_DIR" +[[ -n ${ZINIT[ZCOMPDUMP_PATH]} ]] && ZINIT[ZCOMPDUMP_PATH]=${~ZINIT[ZCOMPDUMP_PATH]} + +ZINIT[UPAR]=";:^[[A;:^[OA;:\\e[A;:\\eOA;:${termcap[ku]/$'\e'/^\[};:${terminfo[kcuu1]/$'\e'/^\[};:" +ZINIT[DOWNAR]=";:^[[B;:^[OB;:\\e[B;:\\eOB;:${termcap[kd]/$'\e'/^\[};:${terminfo[kcud1]/$'\e'/^\[};:" +ZINIT[RIGHTAR]=";:^[[C;:^[OC;:\\e[C;:\\eOC;:${termcap[kr]/$'\e'/^\[};:${terminfo[kcuf1]/$'\e'/^\[};:" +ZINIT[LEFTAR]=";:^[[D;:^[OD;:\\e[D;:\\eOD;:${termcap[kl]/$'\e'/^\[};:${terminfo[kcub1]/$'\e'/^\[};:" + +builtin autoload -Uz is-at-least +is-at-least 5.1 && ZINIT[NEW_AUTOLOAD]=1 || ZINIT[NEW_AUTOLOAD]=0 +#is-at-least 5.4 && ZINIT[NEW_AUTOLOAD]=2 + +# Parameters - shadowing <<< +ZINIT[SHADOWING]=inactive ZINIT[DTRACE]=0 +typeset -gH ZINIT_CUR_PLUGIN= +# >>> +# Parameters - ICE <<< +declare -gA ZINIT_1MAP ZINIT_2MAP +ZINIT_1MAP=( + OMZ:: https://github.com/ohmyzsh/ohmyzsh/trunk/ + PZT:: https://github.com/sorin-ionescu/prezto/trunk/ +) +ZINIT_2MAP=( + OMZ:: https://github.com/ohmyzsh/ohmyzsh/raw/master/ + PZT:: https://github.com/sorin-ionescu/prezto/raw/master/ +) +# >>> + +# Init <<< +zmodload zsh/zutil || return 1 +zmodload zsh/parameter || return 1 +zmodload zsh/terminfo 2>/dev/null +zmodload zsh/termcap 2>/dev/null + +[[ ( ${+terminfo} = 1 && -n ${terminfo[colors]} ) || ( ${+termcap} = 1 && -n ${termcap[Co]} ) ]] && { + ZINIT+=( + col-title "" + col-pname $'\e[33m' + col-uname $'\e[35m' + col-keyword $'\e[32m' + col-note $'\e[33m' + col-error $'\e[31m' + col-p $'\e[01m\e[34m' + col-bar $'\e[01m\e[35m' + col-info $'\e[32m' + col-info2 $'\e[32m' + col-uninst $'\e[01m\e[34m' + col-success $'\e[01m\e[32m' + col-failure $'\e[31m' + col-rst $'\e[0m' + col-bold $'\e[1m' + + col-pre $'\e[38;5;141m' + col-msg1 $'\e[0m' + col-msg2 $'\e[38;5;166m' + col-obj $'\e[38;5;221m' + col-obj2 $'\e[38;5;140m' + col-file $'\e[38;5;110m' + ) +} + +# List of hooks +typeset -gAH ZINIT_ZLE_HOOKS_LIST +ZINIT_ZLE_HOOKS_LIST=( + zle-line-init 1 + zle-line-finish 1 + paste-insert 1 + zle-isearch-exit 1 + zle-isearch-update 1 + zle-history-line-set 1 + zle-keymap-select 1 +) + +builtin setopt noaliases + +# >>> + +# +# Shadowing-related functions +# + +# FUNCTION: :zinit-reload-and-run <<< +# Marks given function ($3) for autoloading, and executes it triggering the +# load. $1 is the fpath dedicated to the function, $2 are autoload options. +# This function replaces "autoload -X", because using that on older Zsh +# versions causes problems with traps. +# +# So basically one creates function stub that calls :zinit-reload-and-run() +# instead of "autoload -X". +# +# $1 - FPATH dedicated to function +# $2 - autoload options +# $3 - function name (one that needs autoloading) +# +# Author: Bart Schaefer +:zinit-reload-and-run () { + local fpath_prefix="$1" autoload_opts="$2" func="$3" + shift 3 + + # Unfunction caller function (its name is given) + unfunction -- "$func" + + local -a __fpath + __fpath=( ${fpath[@]} ) + local -a +h fpath + # See #127 + [[ $FPATH != *${${(@0)fpath_prefix}[1]}* ]] && \ + fpath=( ${(@0)fpath_prefix} ${__fpath[@]} ) + + # After this the function exists again + builtin autoload ${(s: :)autoload_opts} -- "$func" + + # User wanted to call the function, not only load it + "$func" "$@" +} # >>> +# FUNCTION: :zinit-shadow-autoload <<< +# Function defined to hijack plugin's calls to `autoload' builtin. +# +# The hijacking is not only to gather report data, but also to +# run custom `autoload' function, that doesn't need FPATH. +:zinit-shadow-autoload () { + builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ + typesetsilent noshortloops unset + local -a opts + local func + + zparseopts -D -a opts ${(s::):-RTUXdkmrtWz} + + [[ $ZINIT[CUR_USR] = % ]] && \ + local PLUGIN_DIR="$ZINIT_CUR_PLUGIN" || \ + local PLUGIN_DIR="${ZINIT[PLUGINS_DIR]}/${${ZINIT[CUR_USR]}:+${ZINIT[CUR_USR]}---}${ZINIT_CUR_PLUGIN//\//---}" + + if (( ${+opts[(r)-X]} )); then + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: Failed autoload ${(j: :)opts[@]} $*" + print -u2 "builtin autoload required for ${(j: :)opts[@]}" + return 1 + fi + if (( ${+opts[(r)-w]} )); then + .zinit-add-report "${ZINIT[CUR_USPL2]}" "-w-Autoload ${(j: :)opts[@]} ${(j: :)@}" + local +h FPATH="$PLUGINS_DIR:$FPATH" + builtin autoload ${opts[@]} "$@" + return 0 + fi + if [[ -n ${(M)@:#+X} ]]; then + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Autoload +X ${opts:+${(j: :)opts[@]} }${(j: :)${@:#+X}}" + local +h FPATH="$PLUGINS_DIR:$FPATH" + builtin autoload +X ${opts[@]} "${@:#+X}" + return 0 + fi + # Report ZPLUGIN's "native" autoloads + for func; do + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Autoload $func${opts:+ with options ${(j: :)opts[@]}}" + done + + local -a fpath_elements + fpath_elements=( ${fpath[(r)$PLUGIN_DIR/*]} ) + + for func; do + # Real autoload doesn't touch function if it already exists + # Author of the idea of FPATH-clean autoloading: Bart Schaefer + if (( ${+functions[$func]} != 1 )); then + builtin setopt noaliases + if [[ ${ZINIT[NEW_AUTOLOAD]} = 2 ]]; then + builtin autoload ${opts[@]} "$PLUGIN_DIR/$func" + elif [[ ${ZINIT[NEW_AUTOLOAD]} = 1 ]]; then + eval "function ${(q)func} { + local -a fpath + fpath=( ${(qqq)PLUGIN_DIR} ${(qqq@)fpath_elements} ${(qqq@)fpath} ) + builtin autoload -X ${(j: :)${(q-)opts[@]}} + }" + else + eval "function ${(q)func} { + :zinit-reload-and-run ${(qqq)PLUGIN_DIR}"$'\0'"${(pj,\0,)${(qqq)fpath_elements[@]}} ${(qq)opts[*]} ${(q)func} "'"$@" + }' + fi + builtin unsetopt noaliases + fi + done + + return 0 +} # >>> +# FUNCTION: :zinit-shadow-bindkey <<< +# Function defined to hijack plugin's calls to `bindkey' builtin. +# +# The hijacking is to gather report data (which is used in unload). +:zinit-shadow-bindkey() { + builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ + typesetsilent noshortloops unset + is-at-least 5.3 && \ + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Bindkey ${(j: :)${(q+)@}}" || \ + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Bindkey ${(j: :)${(q)@}}" + + # Remember to perform the actual bindkey call + typeset -a pos + pos=( "$@" ) + + # Check if we have regular bindkey call, i.e. + # with no options or with -s, plus possible -M + # option + local -A opts + zparseopts -A opts -D ${(s::):-lLdDAmrsevaR} M: N: + + if (( ${#opts} == 0 || + ( ${#opts} == 1 && ${+opts[-M]} ) || + ( ${#opts} == 1 && ${+opts[-R]} ) || + ( ${#opts} == 1 && ${+opts[-s]} ) || + ( ${#opts} <= 2 && ${+opts[-M]} && ${+opts[-s]} ) || + ( ${#opts} <= 2 && ${+opts[-M]} && ${+opts[-R]} ) + )); then + local string="${(q)1}" widget="${(q)2}" + local quoted + + if [[ -n ${ZINIT_ICE[bindmap]} && ${ZINIT_CUR_BIND_MAP[empty]} -eq 1 ]]; then + local -a pairs + pairs=( "${(@s,;,)ZINIT_ICE[bindmap]}" ) + () { + builtin setopt localoptions extendedglob noksharrays noshwordsplit; + pairs=( "${(@)${(@)${(@s:->:)pairs}##[[:space:]]##}%%[[:space:]]##}" ) + } + ZINIT_CUR_BIND_MAP=( empty 0 ) + (( ${#pairs} > 1 && ${#pairs[@]} % 2 == 0 )) && ZINIT_CUR_BIND_MAP+=( "${pairs[@]}" ) + fi + + 1="${1#"${1%%[! $'\t']*}"}" # leading whitespace + 1="${1%"${1##*[! $'\t']}"}" # trailing whitespace + local bmap_val="${ZINIT_CUR_BIND_MAP[${1}]}" + if [[ -n $bmap_val ]]; then + string="${(q)bmap_val}" + pos[1]="$bmap_val" + .zinit-add-report "${ZINIT[CUR_USPL2]}" ":::Bindkey: combination <$1> changed to <$bmap_val>${${(M)bmap_val:#hold}:+, i.e. ${ZINIT[col-error]}unmapped${ZINIT[col-rst]}}" + (( 1 )) + elif [[ ( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[UPAR]}} && -n ${${ZINIT[UPAR]}[(r);:${(q)1};:]} ) || \ + ( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[DOWNAR]}} && -n ${${ZINIT[DOWNAR]}[(r);:${(q)1};:]} ) || \ + ( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[RIGHTAR]}} && -n ${${ZINIT[RIGHTAR]}[(r);:${(q)1};:]} ) || \ + ( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[LEFTAR]}} && -n ${${ZINIT[LEFTAR]}[(r);:${(q)1};:]} ) + ]]; then + string="${(q)bmap_val}" + pos[1]="$bmap_val" + .zinit-add-report "${ZINIT[CUR_USPL2]}" ":::Bindkey: combination <$1> recognized as cursor-key and changed to <${bmap_val}>${${(M)bmap_val:#hold}:+, i.e. ${ZINIT[col-error]}unmapped${ZINIT[col-rst]}}" + fi + [[ $bmap_val = hold ]] && return 0 + + local prev="${(q)${(s: :)$(builtin bindkey ${(Q)string})}[-1]#undefined-key}" + + # "-M map" given? + if (( ${+opts[-M]} )); then + local Mopt=-M + local Marg="${opts[-M]}" + + Mopt="${(q)Mopt}" + Marg="${(q)Marg}" + + quoted="$string $widget $prev $Mopt $Marg" + else + quoted="$string $widget $prev" + fi + + # -R given? + if (( ${+opts[-R]} )); then + local Ropt=-R + Ropt="${(q)Ropt}" + + if (( ${+opts[-M]} )); then + quoted="$quoted $Ropt" + else + # Two empty fields for non-existent -M arg + local space=_ + space="${(q)space}" + quoted="$quoted $space $space $Ropt" + fi + fi + + quoted="${(q)quoted}" + + # Remember the bindkey, only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[BINDKEYS__${ZINIT[CUR_USPL2]}]+="$quoted " + # Remember for dtrace + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[BINDKEYS___dtrace/_dtrace]+="$quoted " + else + # bindkey -A newkeymap main? + # Negative indices for KSH_ARRAYS immunity + if [[ ${#opts} -eq 1 && ${+opts[-A]} = 1 && ${#pos} = 3 && ${pos[-1]} = main && ${pos[-2]} != -A ]]; then + # Save a copy of main keymap + (( ZINIT[BINDKEY_MAIN_IDX] = ${ZINIT[BINDKEY_MAIN_IDX]:-0} + 1 )) + local pname="${ZINIT_CUR_PLUGIN:-_dtrace}" + local name="${(q)pname}-main-${ZINIT[BINDKEY_MAIN_IDX]}" + builtin bindkey -N "$name" main + + # Remember occurence of main keymap substitution, to revert on unload + local keys=_ widget=_ prev= optA=-A mapname="${name}" optR=_ + local quoted="${(q)keys} ${(q)widget} ${(q)prev} ${(q)optA} ${(q)mapname} ${(q)optR}" + quoted="${(q)quoted}" + + # Remember the bindkey, only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[BINDKEYS__${ZINIT[CUR_USPL2]}]+="$quoted " + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[BINDKEYS___dtrace/_dtrace]+="$quoted " + + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: keymap \`main' copied to \`${name}' because of \`${pos[-2]}' substitution" + # bindkey -N newkeymap [other] + elif [[ ${#opts} -eq 1 && ${+opts[-N]} = 1 ]]; then + local Nopt=-N + local Narg="${opts[-N]}" + + local keys=_ widget=_ prev= optN=-N mapname="${Narg}" optR=_ + local quoted="${(q)keys} ${(q)widget} ${(q)prev} ${(q)optN} ${(q)mapname} ${(q)optR}" + quoted="${(q)quoted}" + + # Remember the bindkey, only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[BINDKEYS__${ZINIT[CUR_USPL2]}]+="$quoted " + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[BINDKEYS___dtrace/_dtrace]+="$quoted " + else + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: last bindkey used non-typical options: ${(kv)opts[*]}" + fi + fi + + # Actual bindkey + builtin bindkey "${pos[@]}" + return $? # testable +} # >>> +# FUNCTION: :zinit-shadow-zstyle <<< +# Function defined to hijack plugin's calls to `zstyle' builtin. +# +# The hijacking is to gather report data (which is used in unload). +:zinit-shadow-zstyle() { + builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ + typesetsilent noshortloops unset + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Zstyle $*" + + # Remember to perform the actual zstyle call + typeset -a pos + pos=( "$@" ) + + # Check if we have regular zstyle call, i.e. + # with no options or with -e + local -a opts + zparseopts -a opts -D ${(s::):-eLdgabsTtm} + + if [[ ${#opts} -eq 0 || ( ${#opts} -eq 1 && ${+opts[(r)-e]} = 1 ) ]]; then + # Have to quote $1, then $2, then concatenate them, then quote them again + local pattern="${(q)1}" style="${(q)2}" + local ps="$pattern $style" + ps="${(q)ps}" + + # Remember the zstyle, only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[ZSTYLES__${ZINIT[CUR_USPL2]}]+="$ps " + # Remember for dtrace + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[ZSTYLES___dtrace/_dtrace]+=$ps + else + if [[ ! ${#opts[@]} = 1 && ( ${+opts[(r)-s]} = 1 || ${+opts[(r)-b]} = 1 || ${+opts[(r)-a]} = 1 || + ${+opts[(r)-t]} = 1 || ${+opts[(r)-T]} = 1 || ${+opts[(r)-m]} = 1 ) + ]]; then + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: last zstyle used non-typical options: ${opts[*]}" + fi + fi + + # Actual zstyle + builtin zstyle "${pos[@]}" + return $? # testable +} # >>> +# FUNCTION: :zinit-shadow-alias <<< +# Function defined to hijack plugin's calls to `alias' builtin. +# +# The hijacking is to gather report data (which is used in unload). +:zinit-shadow-alias() { + builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ + typesetsilent noshortloops unset + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Alias $*" + + # Remember to perform the actual alias call + typeset -a pos + pos=( "$@" ) + + local -a opts + zparseopts -a opts -D ${(s::):-gs} + + local a quoted tmp + for a in "$@"; do + local aname="${a%%[=]*}" + local avalue="${a#*=}" + + # Check if alias is to be redefined + (( ${+aliases[$aname]} )) && .zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: redefining alias \`${aname}', previous value: ${aliases[$aname]}" + + local bname=${(q)aliases[$aname]} + aname="${(q)aname}" + + if (( ${+opts[(r)-s]} )); then + tmp=-s + tmp="${(q)tmp}" + quoted="$aname $bname $tmp" + elif (( ${+opts[(r)-g]} )); then + tmp=-g + tmp="${(q)tmp}" + quoted="$aname $bname $tmp" + else + quoted="$aname $bname" + fi + + quoted="${(q)quoted}" + + # Remember the alias, only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[ALIASES__${ZINIT[CUR_USPL2]}]+="$quoted " + # Remember for dtrace + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[ALIASES___dtrace/_dtrace]+="$quoted " + done + + # Actual alias + builtin alias "${pos[@]}" + return $? # testable +} # >>> +# FUNCTION: :zinit-shadow-zle <<< +# Function defined to hijack plugin's calls to `zle' builtin. +# +# The hijacking is to gather report data (which is used in unload). +:zinit-shadow-zle() { + builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ + typesetsilent noshortloops unset + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Zle $*" + + # Remember to perform the actual zle call + typeset -a pos + pos=( "$@" ) + + set -- "${@:#--}" + + # Try to catch game-changing "-N" + if [[ ( $1 = -N && ( $# = 2 || $# = 3 ) ) || ( $1 = -C && $# = 4 ) ]]; then + # Hooks + if [[ ${ZINIT_ZLE_HOOKS_LIST[$2]} = 1 ]]; then + local quoted="$2" + quoted="${(q)quoted}" + # Remember only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[WIDGETS_DELETE__${ZINIT[CUR_USPL2]}]+="$quoted " + # Remember for dtrace + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[WIDGETS_DELETE___dtrace/_dtrace]+="$quoted " + # These will be saved and restored + elif (( ${+widgets[$2]} )); then + # Have to remember original widget "$2" and + # the copy that it's going to be done + local widname="$2" targetfun="${${${(M)1:#-C}:+$4}:-$3}" + local completion_widget="${${(M)1:#-C}:+$3}" + local saved_widcontents="${widgets[$widname]}" + + widname="${(q)widname}" + completion_widget="${(q)completion_widget}" + targetfun="${(q)targetfun}" + saved_widcontents="${(q)saved_widcontents}" + local quoted="$1 $widname $completion_widget $targetfun $saved_widcontents" + quoted="${(q)quoted}" + # Remember only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[WIDGETS_SAVED__${ZINIT[CUR_USPL2]}]+="$quoted " + # Remember for dtrace + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[WIDGETS_SAVED___dtrace/_dtrace]+="$quoted " + # These will be deleted + else + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Note: a new widget created via zle -N: \`$2'" + local quoted="$2" + quoted="${(q)quoted}" + # Remember only when load is in progress (it can be dstart that leads execution here) + [[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[WIDGETS_DELETE__${ZINIT[CUR_USPL2]}]+="$quoted " + # Remember for dtrace + [[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[WIDGETS_DELETE___dtrace/_dtrace]+="$quoted " + fi + fi + + # Actual zle + builtin zle "${pos[@]}" + return $? # testable +} # >>> +# FUNCTION: :zinit-shadow-compdef <<< +# Function defined to hijack plugin's calls to `compdef' function. +# The hijacking is not only for reporting, but also to save compdef +# calls so that `compinit' can be called after loading plugins. +:zinit-shadow-compdef() { + builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ + typesetsilent noshortloops unset + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Saving \`compdef $*' for replay" + ZINIT_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" ) + + return 0 # testable +} # >>> +# FUNCTION: .zinit-shadow-on <<< +# Turn on shadowing of builtins and functions according to passed +# mode ("load", "light", "light-b" or "compdef"). The shadowing is +# to gather report data, and to hijack `autoload', `bindkey' and +# `compdef' calls. +.zinit-shadow-on() { + local mode="$1" + + # Enable shadowing only once + # + # One could expect possibility of widening of shadowing, however + # such sequence doesn't exist, e.g. "light" then "load"/"dtrace", + # "compdef" then "load"/"dtrace", "light" then "compdef", + # "compdef" then "light" + # + # It is always "dtrace" then "load" (i.e. dtrace then load) + # "dtrace" then "light" (i.e. dtrace then light load) + # "dtrace" then "compdef" (i.e. dtrace then snippet) + [[ ${ZINIT[SHADOWING]} != inactive ]] && builtin return 0 + + ZINIT[SHADOWING]="$mode" + + # The point about backuping is: does the key exist in functions array + # If it does exist, then it will also exist as ZINIT[bkp-*] + + # Defensive code, shouldn't be needed + builtin unset "ZINIT[bkp-autoload]" "ZINIT[bkp-compdef]" # 0, E. + + if [[ $mode != compdef ]]; then + # 0. Used, but not in temporary restoration, which doesn't happen for autoload + (( ${+functions[autoload]} )) && ZINIT[bkp-autoload]="${functions[autoload]}" + functions[autoload]=':zinit-shadow-autoload "$@";' + fi + + # E. Always shadow compdef + (( ${+functions[compdef]} )) && ZINIT[bkp-compdef]="${functions[compdef]}" + functions[compdef]=':zinit-shadow-compdef "$@";' + + # Light and compdef shadowing stops here. Dtrace and load go on + [[ ( $mode = light && ${+ZINIT_ICE[trackbinds]} -eq 0 ) || $mode = compdef ]] && return 0 + + # Defensive code, shouldn't be needed. A, B, C, D + builtin unset "ZINIT[bkp-bindkey]" "ZINIT[bkp-zstyle]" "ZINIT[bkp-alias]" "ZINIT[bkp-zle]" + + # A. + (( ${+functions[bindkey]} )) && ZINIT[bkp-bindkey]="${functions[bindkey]}" + functions[bindkey]=':zinit-shadow-bindkey "$@";' + + # B, when `zinit light -b ...' or when `zinit ice trackbinds ...; zinit light ...' + [[ $mode = light-b || ( $mode = light && ${+ZINIT_ICE[trackbinds]} -eq 1 ) ]] && return 0 + + # B. + (( ${+functions[zstyle]} )) && ZINIT[bkp-zstyle]="${functions[zstyle]}" + functions[zstyle]=':zinit-shadow-zstyle "$@";' + + # C. + (( ${+functions[alias]} )) && ZINIT[bkp-alias]="${functions[alias]}" + functions[alias]=':zinit-shadow-alias "$@";' + + # D. + (( ${+functions[zle]} )) && ZINIT[bkp-zle]="${functions[zle]}" + functions[zle]=':zinit-shadow-zle "$@";' + + builtin return 0 +} # >>> +# FUNCTION: .zinit-shadow-off <<< +# Turn off shadowing completely for a given mode ("load", "light", +# "light-b" (i.e. the `trackbinds' mode) or "compdef"). +.zinit-shadow-off() { + builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ + typesetsilent noshortloops unset noaliases + local mode="$1" + + # Disable shadowing only once + # Disable shadowing only the way it was enabled first + [[ ${ZINIT[SHADOWING]} = inactive || ${ZINIT[SHADOWING]} != $mode ]] && return 0 + + ZINIT[SHADOWING]=inactive + + if [[ $mode != compdef ]]; then + # 0. Unfunction autoload + (( ${+ZINIT[bkp-autoload]} )) && functions[autoload]="${ZINIT[bkp-autoload]}" || unfunction autoload + fi + + # E. Restore original compdef if it existed + (( ${+ZINIT[bkp-compdef]} )) && functions[compdef]="${ZINIT[bkp-compdef]}" || unfunction compdef + + # Light and compdef shadowing stops here + [[ ( $mode = light && ${+ZINIT_ICE[trackbinds]} -eq 0 ) || $mode = compdef ]] && return 0 + + # Unfunction shadowing functions + + # A. + (( ${+ZINIT[bkp-bindkey]} )) && functions[bindkey]="${ZINIT[bkp-bindkey]}" || unfunction bindkey + + # When `zinit light -b ...' or when `zinit ice trackbinds ...; zinit light ...' + [[ $mode = light-b || ( $mode = light && ${+ZINIT_ICE[trackbinds]} -eq 1 ) ]] && return 0 + + # B. + (( ${+ZINIT[bkp-zstyle]} )) && functions[zstyle]="${ZINIT[bkp-zstyle]}" || unfunction zstyle + # C. + (( ${+ZINIT[bkp-alias]} )) && functions[alias]="${ZINIT[bkp-alias]}" || unfunction alias + # D. + (( ${+ZINIT[bkp-zle]} )) && functions[zle]="${ZINIT[bkp-zle]}" || unfunction zle + + return 0 +} # >>> +# FUNCTION: pmodload <<< +# {function:pmodload} Compatibility with Prezto. Calls can be recursive. +(( ${+functions[pmodload]} )) || pmodload() { + while (( $# )); do + if zstyle -t ":prezto:module:$1" loaded 'yes' 'no'; then + shift + continue + else + [[ -z ${ZINIT_SNIPPETS[PZT::modules/$1${ZINIT_ICE[svn]-/init.zsh}]} && -z ${ZINIT_SNIPPETS[https://github.com/sorin-ionescu/prezto/trunk/modules/$1${ZINIT_ICE[svn]-/init.zsh}]} ]] && .zinit-load-snippet PZT::modules/"$1${ZINIT_ICE[svn]-/init.zsh}" + shift + fi + done +} +# >>> +# FUNCTION: .zinit-wrap-track-functions <<< +.zinit-wrap-track-functions() { + local user="$1" plugin="$2" id_as="$3" f + local -a wt + wt=( ${(@s.;.)ZINIT_ICE[wrap-track]} ) + for f in ${wt[@]}; do + functions[${f}-zinit-bkp]="${functions[$f]}" + eval " +function $f { + ZINIT[CUR_USR]=\"$user\" ZINIT_CUR_PLUGIN=\"$plugin\" ZINIT[CUR_USPL2]=\"$id_as\" + .zinit-add-report \"\${ZINIT[CUR_USPL2]}\" \"Note: === Starting to track function: $f ===\" + .zinit-diff \"\${ZINIT[CUR_USPL2]}\" begin + .zinit-shadow-on load + functions[${f}]=\${functions[${f}-zinit-bkp]} + ${f} \"\$@\" + .zinit-shadow-off load + .zinit-diff \"\${ZINIT[CUR_USPL2]}\" end + .zinit-add-report \"\${ZINIT[CUR_USPL2]}\" \"Note: === Ended tracking function: $f ===\" + ZINIT[CUR_USR]= ZINIT_CUR_PLUGIN= ZINIT[CUR_USPL2]= +}" + done +} +# >>> + +# +# Diff functions +# + +# FUNCTION: .zinit-diff-functions <<< +# Implements detection of newly created functions. Performs +# data gathering, computation is done in *-compute(). +# +# $1 - user/plugin (i.e. uspl2 format) +# $2 - command, can be "begin" or "end" +.zinit-diff-functions() { + local uspl2="$1" + local cmd="$2" + + [[ $cmd = begin ]] && \ + { [[ -z ${ZINIT[FUNCTIONS_BEFORE__$uspl2]} ]] && \ + ZINIT[FUNCTIONS_BEFORE__$uspl2]="${(j: :)${(qk)functions[@]}}" + } || \ + ZINIT[FUNCTIONS_AFTER__$uspl2]+=" ${(j: :)${(qk)functions[@]}}" +} # >>> +# FUNCTION: .zinit-diff-options <<< +# Implements detection of change in option state. Performs +# data gathering, computation is done in *-compute(). +# +# $1 - user/plugin (i.e. uspl2 format) +# $2 - command, can be "begin" or "end" +.zinit-diff-options() { + local IFS=" " + + [[ $2 = begin ]] && \ + { [[ -z ${ZINIT[OPTIONS_BEFORE__$uspl2]} ]] && \ + ZINIT[OPTIONS_BEFORE__$1]="${(kv)options[@]}" + } || \ + ZINIT[OPTIONS_AFTER__$1]+=" ${(kv)options[@]}" +} # >>> +# FUNCTION: .zinit-diff-env <<< +# Implements detection of change in PATH and FPATH. +# +# $1 - user/plugin (i.e. uspl2 format) +# $2 - command, can be "begin" or "end" +.zinit-diff-env() { + typeset -a tmp + local IFS=" " + + [[ $2 = begin ]] && { + { [[ -z ${ZINIT[PATH_BEFORE__$uspl2]} ]] && \ + tmp=( "${(q)path[@]}" ) + ZINIT[PATH_BEFORE__$1]="${tmp[*]}" + } + { [[ -z ${ZINIT[FPATH_BEFORE__$uspl2]} ]] && \ + tmp=( "${(q)fpath[@]}" ) + ZINIT[FPATH_BEFORE__$1]="${tmp[*]}" + } + } || { + tmp=( "${(q)path[@]}" ) + ZINIT[PATH_AFTER__$1]+=" ${tmp[*]}" + tmp=( "${(q)fpath[@]}" ) + ZINIT[FPATH_AFTER__$1]+=" ${tmp[*]}" + } +} # >>> +# FUNCTION: .zinit-diff-parameter <<< +# Implements detection of change in any parameter's existence and type. +# Performs data gathering, computation is done in *-compute(). +# +# $1 - user/plugin (i.e. uspl2 format) +# $2 - command, can be "begin" or "end" +.zinit-diff-parameter() { + typeset -a tmp + + [[ $2 = begin ]] && { + { [[ -z ${ZINIT[PARAMETERS_BEFORE__$uspl2]} ]] && \ + ZINIT[PARAMETERS_BEFORE__$1]="${(j: :)${(qkv)parameters[@]}}" + } + } || { + ZINIT[PARAMETERS_AFTER__$1]+=" ${(j: :)${(qkv)parameters[@]}}" + } +} # >>> +# FUNCTION: .zinit-diff <<< +# Performs diff actions of all types +.zinit-diff() { + .zinit-diff-functions "$1" "$2" + .zinit-diff-options "$1" "$2" + .zinit-diff-env "$1" "$2" + .zinit-diff-parameter "$1" "$2" +} +# >>> + +# +# Utility functions +# + +# FUNCTION: @zinit-substitute <<< +@zinit-substitute() { + local -A __subst_map + __subst_map=( + "%ID%" "${id_as_clean:-$id_as}" + "%USER%" "$user" + "%PLUGIN%" "${plugin:-$save_url}" + "%URL%" "${save_url:-${user:+$user/}$plugin}" + "%DIR%" "${local_path:-$local_dir${dirname:+/$dirname}}" + '$ZPFX' "$ZPFX" + '${ZPFX}' "$ZPFX" + '%OS%' "${OSTYPE%(-gnu|[0-9]##)}" '%MACH%' "$MACHTYPE" '%CPU%' "$CPUTYPE" + '%VENDOR%' "$VENDOR" '%HOST%' "$HOST" '%UID%' "$UID" '%GID%' "$GID" + ) + if [[ -n ${ZINIT_ICE[param]} && ${ZINIT[SUBST_DONE_FOR]} != ${ZINIT_ICE[param]} ]] { + ZINIT[SUBST_DONE_FOR]="${ZINIT_ICE[param]}" + ZINIT[PARAM_SUBST]= + local -a __params + __params=( ${(s.;.)ZINIT_ICE[param]} ) + local __param __from __to + for __param ( ${__params[@]} ) { + local __from="${${__param%%([[:space:]]|)(->|β†’)*}##[[:space:]]##}" \ + __to="${${__param##*(->|β†’)([[:space:]]|)}%[[:space:]]}" + ZINIT[PARAM_SUBST]+="%${(q)__from}% ${(q)__to} " + } + } + + local -a __add + __add=( "${ZINIT_ICE[param]:+${(@Q)${(@z)ZINIT[PARAM_SUBST]}}}" ) + (( ${#__add} % 2 == 0 )) && __subst_map+=( "${__add[@]}" ) + + local __var_name MATCH + integer MBEGIN MEND + () { + setopt localoptions extendedglob + for __var_name; do + local __value="${(P)__var_name}" + __value="${__value//(#m)(%[a-zA-Z0-9]##%|\$ZPFX|\$\{ZPFX\})/${__subst_map[$MATCH]}}" + : "${(P)__var_name::=$__value}" + done + } "$@" +} +# >>> +# FUNCTION: .zinit-any-to-user-plugin <<< +# Allows elastic plugin-spec across the code. +# +# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) +# $2 - plugin (only when $1 - i.e. user - given) +# +# Returns user and plugin in $reply +# +.zinit-any-to-user-plugin() { + # Two components given? + # That's a pretty fast track to call this function this way + if [[ -n $2 ]];then + 2=${~2} + reply=( "${1:-${${(M)2#/}:+%}}" "${${${(M)1#%}:+$2}:-${2//---//}}" ) + return 0 + fi + + # Is it absolute path? + if [[ $1 = /* ]]; then + reply=( "%" "$1" ) + return 0 + fi + + # Is it absolute path in zinit format? + if [[ $1 = %* ]]; then + reply=( "%" "${${${1/\%HOME/$HOME}/\%SNIPPETS/${ZINIT[SNIPPETS_DIR]}}#%}" ) + reply[2]=${~reply[2]} + return 0 + fi + + # Rest is for single component given + # It doesn't touch $2 + + if [[ $1 = */* ]]; then + reply=( "${1%%/*}" "${1#*/}" ) + return 0 + fi + + reply=( "${${(M)1#*---}%---}" "${${${1#*---}//---//}:-_unknown}" ) + + return 0 +} # >>> +# FUNCTION: .zinit-find-other-matches <<< +# Plugin's main source file is in general `name.plugin.zsh'. However, +# there can be different conventions, if that file is not found, then +# this functions examines other conventions in order of most expected +# sanity. +.zinit-find-other-matches() { + local pdir_path="$1" pbase="$2" + + if [[ -e $pdir_path/init.zsh ]]; then + reply=( "$pdir_path/init.zsh" ) + elif [[ -e $pdir_path/${pbase}.zsh-theme ]]; then + reply=( "$pdir_path/${pbase}.zsh-theme" ) + elif [[ -e $pdir_path/${pbase}.theme.zsh ]]; then + reply=( "$pdir_path/${pbase}.theme.zsh" ) + else + reply=( + $pdir_path/*.plugin.zsh(DN) $pdir_path/*.zsh-theme(DN) $pdir_path/init.zsh(DN) + $pdir_path/*.zsh(DN) $pdir_path/*.sh(DN) $pdir_path/.zshrc(DN) + ) + fi +} # >>> +# FUNCTION: .zinit-register-plugin <<< +# Adds the plugin to ZINIT_REGISTERED_PLUGINS array and to the +# zsh_loaded_plugins array (managed according to the plugin standard: +# http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html) +.zinit-register-plugin() { + local uspl2="$1" mode="$2" teleid="$3" + integer ret=0 + + if [[ -z ${ZINIT_REGISTERED_PLUGINS[(r)$uspl2]} ]]; then + ZINIT_REGISTERED_PLUGINS+=( "$uspl2" ) + else + # Allow overwrite-load, however warn about it + [[ -z ${ZINIT[TEST]}${${+ZINIT_ICE[wait]}:#0}${ZINIT_ICE[load]}${ZINIT_ICE[subscribe]} && ${ZINIT[MUTE_WARNINGS]} != 1 ]] && print "Warning: plugin \`$uspl2' already registered, will overwrite-load" + ret=1 + fi + + # Support Zsh plugin standard + zsh_loaded_plugins+=( "$teleid" ) + + # Full or light load? + [[ $mode = light ]] && ZINIT_REGISTERED_STATES[$uspl2]=1 || ZINIT_REGISTERED_STATES[$uspl2]=2 + + ZINIT_REPORTS[$uspl2]= ZINIT_CUR_BIND_MAP=( empty 1 ) + # Functions + ZINIT[FUNCTIONS_BEFORE__$uspl2]= ZINIT[FUNCTIONS_AFTER__$uspl2]= + ZINIT[FUNCTIONS__$uspl2]= + # Objects + ZINIT[ZSTYLES__$uspl2]= ZINIT[BINDKEYS__$uspl2]= + ZINIT[ALIASES__$uspl2]= + # Widgets + ZINIT[WIDGETS_SAVED__$uspl2]= ZINIT[WIDGETS_DELETE__$uspl2]= + # Rest (options and (f)path) + ZINIT[OPTIONS__$uspl2]= ZINIT[PATH__$uspl2]= + ZINIT[OPTIONS_BEFORE__$uspl2]= ZINIT[OPTIONS_AFTER__$uspl2]= + ZINIT[FPATH__$uspl2]= + + return $ret +} # >>> +# FUNCTION: @zinit-register-z-annex <<< +# Registers the z-annex inside Zinit – i.e. an Zinit extension +@zinit-register-annex() { + local name="$1" type="$2" handler="$3" helphandler="$4" icemods="$5" key="z-annex ${(q)2}" + ZINIT_EXTS[seqno]=$(( ${ZINIT_EXTS[seqno]:-0} + 1 )) + ZINIT_EXTS[$key${${(M)type#hook:}:+ ${ZINIT_EXTS[seqno]}}]="${ZINIT_EXTS[seqno]} z-annex-data: ${(q)name} ${(q)type} ${(q)handler} ${(q)helphandler} ${(q)icemods}" + ZINIT_EXTS[ice-mods]="${ZINIT_EXTS[ice-mods]}${icemods:+|}$icemods" +} +# >>> +# FUNCTION: @zsh-plugin-run-on-update <<< +# The Plugin Standard required mechanism, see: +# http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +@zsh-plugin-run-on-unload() { + ZINIT_ICE[ps-on-unload]="${(j.; .)@}" + .zinit-pack-ice "$id_as" "" +} +# >>> +# FUNCTION: @zsh-plugin-run-on-update <<< +# The Plugin Standard required mechanism +@zsh-plugin-run-on-update() { + ZINIT_ICE[ps-on-update]="${(j.; .)@}" + .zinit-pack-ice "$id_as" "" +} +# >>> + +# +# Remaining functions +# + +# FUNCTION: .zinit-prepare-home <<< +# Creates all directories needed by Zinit, first checks if they +# already exist. +.zinit-prepare-home() { + [[ -n ${ZINIT[HOME_READY]} ]] && return + ZINIT[HOME_READY]=1 + + [[ ! -d ${ZINIT[HOME_DIR]} ]] && { + command mkdir -p "${ZINIT[HOME_DIR]}" + # For compaudit + command chmod go-w "${ZINIT[HOME_DIR]}" + # Also set up */bin and ZPFX in general + command mkdir 2>/dev/null -p ${ZPFX}/bin + } + [[ ! -d ${ZINIT[PLUGINS_DIR]}/_local---zinit ]] && { + command rm -rf "${ZINIT[PLUGINS_DIR]}/_local---zplugin" + command mkdir -p "${ZINIT[PLUGINS_DIR]}/_local---zinit" + command chmod go-w "${ZINIT[PLUGINS_DIR]}" + command ln -s "${ZINIT[BIN_DIR]}/_zinit" "${ZINIT[PLUGINS_DIR]}/_local---zinit" + + # Also set up */bin and ZPFX in general + command mkdir 2>/dev/null -p ${ZPFX}/bin + + (( ${+functions[.zinit-setup-plugin-dir]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + .zinit-compinit &>/dev/null + } + [[ ! -d ${ZINIT[COMPLETIONS_DIR]} ]] && { + command mkdir "${ZINIT[COMPLETIONS_DIR]}" + # For compaudit + command chmod go-w "${ZINIT[COMPLETIONS_DIR]}" + + # Symlink _zinit completion into _local---zinit directory + command ln -s "${ZINIT[PLUGINS_DIR]}/_local---zinit/_zinit" "${ZINIT[COMPLETIONS_DIR]}" + + # Also set up */bin and ZPFX in general + command mkdir 2>/dev/null -p ${ZPFX}/bin + } + [[ ! -d ${ZINIT[SNIPPETS_DIR]} ]] && { + command mkdir "${ZINIT[SNIPPETS_DIR]}" + command chmod go-w "${ZINIT[SNIPPETS_DIR]}" + ( cd ${ZINIT[SNIPPETS_DIR]}; command ln -s OMZ::plugins plugins; ) + + # Also create the SERVICES_DIR + command mkdir -p "${ZINIT[SERVICES_DIR]}" + command chmod go-w "${ZINIT[SERVICES_DIR]}" + + # Also set up */bin and ZPFX in general + command mkdir 2>/dev/null -p ${ZPFX}/bin + } +} # >>> +# FUNCTION: .zinit-load-ices <<< +.zinit-load-ices() { + local id_as="$1" __key __path + local -a ice_order + ice_order=( + svn proto from teleid bindmap cloneopts id-as depth if wait load + unload blockf pick bpick src as ver silent lucid notify mv cp + atinit atclone atload atpull nocd run-atpull has cloneonly make + service trackbinds multisrc compile nocompile nocompletions + reset-prompt wrap-track reset sh \!sh bash \!bash ksh \!ksh csh + \!csh aliases countdown ps-on-unload ps-on-update trigger-load + light-mode is-snippet atdelete pack git verbose on-update-of + subscribe + ${(@us.|.)${ZINIT_EXTS[ice-mods]//\'\'/}} + ) + __path=${ZINIT[PLUGINS_DIR]}/${id_as//\//---}/._zinit + [[ -d $__path ]] || __path=${ZINIT[SNIPPETS_DIR]}/$id_as/._zinit + for __key in "${ice_order[@]}"; do + (( ${+ZINIT_ICE[$__key]} )) && [[ ${ZINIT_ICE[$__key]} != +* ]] && continue + [[ -f $__path/$__key ]] && ZINIT_ICE[$__key]="$(<$__path/$__key)" + done + [[ -n ${ZINIT_ICE[on-update-of]} ]] && ZINIT_ICE[subscribe]="${ZINIT_ICE[subscribe]:-${ZINIT_ICE[on-update-of]}}" + [[ ${ZINIT_ICE[as]} = program ]] && ZINIT_ICE[as]=command + [[ -n ${ZINIT_ICE[pick]} ]] && ZINIT_ICE[pick]="${ZINIT_ICE[pick]//\$ZPFX/${ZPFX%/}}" + return 0 +} +# >>> +# FUNCTION: .zinit-load <<< +# Implements the exposed-to-user action of loading a plugin. +# +# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) +# $2 - plugin name, if the third format is used +.zinit-load () { + typeset -F 3 SECONDS=0 + local mode="$3" rst=0 retval=0 key + .zinit-any-to-user-plugin "$1" "$2" + local user="${reply[-2]}" plugin="${reply[-1]}" id_as="${ZINIT_ICE[id-as]:-${reply[-2]}${${reply[-2]:#(%|/)*}:+/}${reply[-1]}}" + ZINIT_ICE[teleid]="${ZINIT_ICE[teleid]:-$user${${user:#(%|/)*}:+/}$plugin}" + + local -a arr + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:preinit <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" plugin "$user" "$plugin" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZINIT[PLUGINS_DIR]}/${id_as//\//---}}" preinit || \ + return $(( 10 - $? )) + done + + if [[ $user != % && ! -d ${ZINIT[PLUGINS_DIR]}/${id_as//\//---} ]]; then + (( ${+functions[.zinit-setup-plugin-dir]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + reply=( "$user" "$plugin" ) REPLY=github + if (( ${+ZINIT_ICE[pack]} )) { + if ! .zinit-get-package "$user" "$plugin" "$id_as" \ + "${ZINIT[PLUGINS_DIR]}/${id_as//\//---}" \ + "${ZINIT_ICE[pack]:-default}" + then + zle && { print; zle .reset-prompt; } + return 1 + fi + id_as="${ZINIT_ICE[id-as]:-${user}${${user:#(%|/)*}:+/}$plugin}" + } + user="${reply[-2]}" plugin="${reply[-1]}" + ZINIT_ICE[teleid]="$user${${user:#(%|/)*}:+/}$plugin" + [[ $REPLY = snippet ]] && { + ZINIT_ICE[id-as]="${ZINIT_ICE[id-as]:-$id_as}" + .zinit-load-snippet $plugin + return $? + } + if ! .zinit-setup-plugin-dir "$user" "$plugin" "$id_as" "$REPLY"; then + zle && { print; zle .reset-prompt; } + return 1 + fi + zle && rst=1 + fi + + ZINIT_SICE[$id_as]= + .zinit-pack-ice "$id_as" + + (( ${+ZINIT_ICE[cloneonly]} )) && return 0 + + .zinit-register-plugin "$id_as" "$mode" "${ZINIT_ICE[teleid]}" + + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atinit <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" plugin "$user" "$plugin" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZINIT[PLUGINS_DIR]}/${id_as//\//---}}" \!atinit || \ + return $(( 10 - $? )) + done + + (( ${+ZINIT_ICE[atinit]} )) && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "${${${(M)user:#%}:+$plugin}:-${ZINIT[PLUGINS_DIR]}/${id_as//\//---}}"; } && eval "${ZINIT_ICE[atinit]}"; ((1)); } || eval "${ZINIT_ICE[atinit]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atinit <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" plugin "$user" "$plugin" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZINIT[PLUGINS_DIR]}/${id_as//\//---}}" atinit || \ + return $(( 10 - $? )) + done + + .zinit-load-plugin "$user" "$plugin" "$id_as" "$mode" "$rst"; retval=$? + (( ${+ZINIT_ICE[notify]} == 1 )) && { [[ $retval -eq 0 || -n ${(M)ZINIT_ICE[notify]#\!} ]] && { local msg; eval "msg=\"${ZINIT_ICE[notify]#\!}\""; .zinit-deploy-message @msg "$msg" } || .zinit-deploy-message @msg "notify: Plugin not loaded / loaded with problem, the return code: $retval"; } + (( ${+ZINIT_ICE[reset-prompt]} == 1 )) && .zinit-deploy-message @rst + ZINIT[TIME_INDEX]=$(( ${ZINIT[TIME_INDEX]:-0} + 1 )) + ZINIT[TIME_${ZINIT[TIME_INDEX]}_${id_as//\//---}]=$SECONDS + ZINIT[AT_TIME_${ZINIT[TIME_INDEX]}_${id_as//\//---}]=$EPOCHREALTIME + return $retval +} # >>> +# FUNCTION: .zinit-load-snippet <<< +# Implements the exposed-to-user action of loading a snippet. +# +# $1 - url (can be local, absolute path) +.zinit-load-snippet() { + typeset -F 3 SECONDS=0 + local -a opts tmp ice + zparseopts -E -D -a opts f -command u i || { print -r -- "Incorrect options (accepted ones: -f, --command)"; return 1; } + local url="$1" + integer correct=0 retval=0 + [[ -o ksharrays ]] && correct=1 + + [[ -n ${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && \ + local -a precm=( + emulate + ${${(M)${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!}:+-R} + ${${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!} + ${${ZINIT_ICE[(i)(\!|)bash]}:+-${(s: :):-o noshglob -o braceexpand -o kshglob}} + -c + ) + # Remove leading whitespace and trailing / + url="${${url#"${url%%[! $'\t']*}"}%/}" + ZINIT_ICE[teleid]="$url" + [[ ${ZINIT_ICE[as]} = null ]] && \ + ZINIT_ICE[pick]="${ZINIT_ICE[pick]:-/dev/null}" + + local local_dir dirname filename save_url="$url" id_as="${ZINIT_ICE[id-as]:-$url}" + [[ -z ${opts[(r)-u]} ]] && .zinit-pack-ice "$id_as" "" + + # Allow things like $OSTYPE in the URL + eval "url=\"$url\"" + + # - case A: called from `update --all', ZINIT_ICE not packed (above), static ice will win + # - case B: called from `snippet', ZINIT_ICE packed, so it will win + # - case C: called from `update', ZINIT_ICE packed, so it will win ← TODO + tmp=( "${(Q@)${(z@)ZINIT_SICE[$id_as]}}" ) + (( ${#tmp} > 1 && ${#tmp} % 2 == 0 )) && { ice=( "${(kv)ZINIT_ICE[@]}" "${tmp[@]}" ); ZINIT_ICE=( "${ice[@]}" ); } + tmp=( 1 ) + id_as="${ZINIT_ICE[id-as]:-$id_as}" + + # Oh-My-Zsh, Prezto and manual shorthands + (( ${+ZINIT_ICE[svn]} )) && { + [[ $url = *(OMZ::|robbyrussell*oh-my-zsh|ohmyzsh/ohmyzsh)* ]] && local ZSH="${ZINIT[SNIPPETS_DIR]}" + url[1-correct,5-correct]="${ZINIT_1MAP[${url[1-correct,5-correct]}]:-${url[1-correct,5-correct]}}" + } || { + url[1-correct,5-correct]="${ZINIT_2MAP[${url[1-correct,5-correct]}]:-${url[1-correct,5-correct]}}" + } + + # Construct containing directory, extract final directory + # into handy-variable $dirname + filename="${${id_as%%\?*}:t}" + dirname="${${id_as%%\?*}:t}" + local_dir="${${${id_as%%\?*}:h}/:\/\//--}" + [[ $local_dir = . ]] && local_dir= || local_dir="${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}" + local_dir="${ZINIT[SNIPPETS_DIR]}${local_dir:+/$local_dir}" + + local -a arr + local key + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:preinit <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" preinit || \ + return $(( 10 - $? )) + done + + # Download or copy the file + if [[ -n ${opts[(r)(-f|-u)]} || ! ( -e $local_dir/$dirname/._zinit || \ + -e $local_dir/$dirname/._zplugin ) + ]]; then + (( ${+functions[.zinit-download-snippet]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + [[ $url = *github.com* && $url != */raw/* ]] && url="${${url/\/blob\///raw/}/\/tree\///raw/}" + .zinit-download-snippet "$save_url" "$url" "$id_as" "$local_dir" "$dirname" "$filename" "${opts[(r)-u]}" || tmp=( 0 ) + fi + + (( ${+ZINIT_ICE[cloneonly]} || !tmp[1-correct] )) && return 0 + + ZINIT_SNIPPETS[$id_as]="$id_as <${${ZINIT_ICE[svn]+svn}:-single file}>" + + [[ -z ${opts[(r)-u]} ]] && { ZINIT[CUR_USPL2]="$id_as"; ZINIT_REPORTS[$id_as]=; } + + [[ -z ${opts[(r)-u]} ]] && { + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atinit <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" \!atinit || \ + return $(( 10 - $? )) + done + } + + (( ${+ZINIT_ICE[atinit]} )) && [[ -z ${opts[(r)-u]} ]] && { local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && eval "${ZINIT_ICE[atinit]}"; ((1)); } || eval "${ZINIT_ICE[atinit]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + + [[ -z ${opts[(r)-u]} ]] && { + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atinit <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" atinit || \ + return $(( 10 - $? )) + done + } + + local -a list + local ZERO + + if [[ -z ${opts[(r)-u]} && -z ${opts[(r)--command]} && ( -z ${ZINIT_ICE[as]} || ${ZINIT_ICE[as]} = null ) ]]; then + # Source the file with compdef shadowing + if [[ ${ZINIT[SHADOWING]} = inactive ]]; then + # Shadowing code is inlined from .zinit-shadow-on + (( ${+functions[compdef]} )) && ZINIT[bkp-compdef]="${functions[compdef]}" || builtin unset "ZINIT[bkp-compdef]" + functions[compdef]=':zinit-shadow-compdef "$@";' + ZINIT[SHADOWING]=1 + else + (( ++ ZINIT[SHADOWING] )) + fi + + # Add to fpath + [[ -d $local_dir/$dirname/functions ]] && { + [[ -z ${fpath[(r)$local_dir/$dirname/functions]} ]] && fpath+=( "$local_dir/$dirname/functions" ) + () { + builtin setopt localoptions extendedglob + autoload $local_dir/$dirname/functions/^([_.]*|prompt_*_setup|README*)(D-.N:t) + } + } + + # Source + if (( ${+ZINIT_ICE[svn]} == 0 )); then + [[ ${+ZINIT_ICE[pick]} = 0 ]] && list=( "$local_dir/$dirname/$filename" ) + [[ -n ${ZINIT_ICE[pick]} ]] && list=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZINIT_ICE[pick]}(DN) ) + else + if [[ -n ${ZINIT_ICE[pick]} ]]; then + list=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZINIT_ICE[pick]}(DN) ) + elif (( ${+ZINIT_ICE[pick]} == 0 )); then + list=( + $local_dir/$dirname/*.plugin.zsh(DN) $local_dir/$dirname/*.zsh-theme(DN) $local_dir/$dirname/init.zsh(DN) + $local_dir/$dirname/*.zsh(DN) $local_dir/$dirname/*.sh(DN) $local_dir/$dirname/.zshrc(DN) + ) + fi + fi + + [[ -f ${list[1-correct]} ]] && { + ZERO="${list[1-correct]}" + (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } + (( 0 == retval )) && [[ $id_as = PZT::* || $id_as = https://github.com/sorin-ionescu/prezto/* ]] && zstyle ":prezto:module:${${id_as%/init.zsh}:t}" loaded 'yes' + (( 1 )) + } || { [[ ${+ZINIT_ICE[pick]} = 1 && -z ${ZINIT_ICE[pick]} || ${ZINIT_ICE[pick]} = /dev/null ]] || { print -r -- "Snippet not loaded ($id_as)"; retval=1; } } + + [[ -n ${ZINIT_ICE[src]} ]] && { ZERO="${${(M)ZINIT_ICE[src]##/*}:-$local_dir/$dirname/${ZINIT_ICE[src]}}"; (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; } + [[ -n ${ZINIT_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; }; eval "reply=(${ZINIT_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$local_dir/$dirname/$fname}"; (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; done; } + + # Run the atload hooks right before atload ice + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atload <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" \!atload + done + + # Run the functions' wrapping & tracking requests + [[ -n ${ZINIT_ICE[wrap-track]} ]] && \ + .zinit-wrap-track-functions "$save_url" "" "$id_as" + + [[ ${ZINIT_ICE[atload][1]} = "!" ]] && { .zinit-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$local_dir/$dirname/-atload-"; local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && builtin eval "${ZINIT_ICE[atload]#\!}"; (( 1 )); } || eval "${ZINIT_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + + (( -- ZINIT[SHADOWING] == 0 )) && { ZINIT[SHADOWING]=inactive; builtin setopt noaliases; (( ${+ZINIT[bkp-compdef]} )) && functions[compdef]="${ZINIT[bkp-compdef]}" || unfunction compdef; builtin setopt aliases; } + elif [[ -n ${opts[(r)--command]} || ${ZINIT_ICE[as]} = command ]]; then + # Subversion - directory and multiple files possible + if (( ${+ZINIT_ICE[svn]} )); then + if [[ -n ${ZINIT_ICE[pick]} ]]; then + list=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZINIT_ICE[pick]}(DN) ) + [[ -n ${list[1-correct]} ]] && local xpath="${list[1-correct]:h}" xfilepath="${list[1-correct]}" + else + local xpath="$local_dir/$dirname" + fi + else + local xpath="$local_dir/$dirname" xfilepath="$local_dir/$dirname/$filename" + # This doesn't make sense, but users may come up with something + [[ -n ${ZINIT_ICE[pick]} ]] && { + list=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZINIT_ICE[pick]}(DN) ) + [[ -n ${list[1-correct]} ]] && xpath="${list[1-correct]:h}" xfilepath="${list[1-correct]}" + } + fi + [[ -z ${opts[(r)-u]} && -n $xpath && -z ${path[(er)$xpath]} ]] && path=( "${xpath%/}" ${path[@]} ) + [[ -n $xfilepath && -f $xfilepath && ! -x "$xfilepath" ]] && command chmod a+x "$xfilepath" ${list[@]:#$xfilepath} + [[ -z ${opts[(r)-u]} && ( -n ${ZINIT_ICE[src]} || -n ${ZINIT_ICE[multisrc]} || ${ZINIT_ICE[atload][1]} = "!" ) ]] && { + if [[ ${ZINIT[SHADOWING]} = inactive ]]; then + # Shadowing code is inlined from .zinit-shadow-on + (( ${+functions[compdef]} )) && ZINIT[bkp-compdef]="${functions[compdef]}" || builtin unset "ZINIT[bkp-compdef]" + functions[compdef]=':zinit-shadow-compdef "$@";' + ZINIT[SHADOWING]=1 + else + (( ++ ZINIT[SHADOWING] )) + fi + } + + if [[ -z ${opts[(r)-u]} ]] { + if [[ -n ${ZINIT_ICE[src]} ]]; then + ZERO="${${(M)ZINIT_ICE[src]##/*}:-$local_dir/$dirname/${ZINIT_ICE[src]}}" + (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } + fi + [[ -n ${ZINIT_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; }; eval "reply=(${ZINIT_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$local_dir/$dirname/$fname}"; (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; done; } + + # Run the atload hooks right before atload ice + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atload <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" \!atload + done + + # Run the functions' wrapping & tracking requests + [[ -n ${ZINIT_ICE[wrap-track]} ]] && \ + .zinit-wrap-track-functions "$save_url" "" "$id_as" + + [[ ${ZINIT_ICE[atload][1]} = "!" ]] && { .zinit-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$local_dir/$dirname/-atload-"; local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && builtin eval "${ZINIT_ICE[atload]#\!}"; ((1)); } || eval "${ZINIT_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + } + + [[ -z ${opts[(r)-u]} && ( -n ${ZINIT_ICE[src]} || -n ${ZINIT_ICE[multisrc]} || ${ZINIT_ICE[atload][1]} = "!" ) ]] && { + (( -- ZINIT[SHADOWING] == 0 )) && { ZINIT[SHADOWING]=inactive; builtin setopt noaliases; (( ${+ZINIT[bkp-compdef]} )) && functions[compdef]="${ZINIT[bkp-compdef]}" || unfunction compdef; builtin setopt aliases; } + } + elif [[ ${ZINIT_ICE[as]} = completion ]]; then + ((1)) + fi + + # Updating – not sourcing, etc. + [[ -n ${opts[(r)-u]} ]] && return 0 + + (( ${+ZINIT_ICE[atload]} )) && [[ ${ZINIT_ICE[atload][1]} != "!" ]] && { ZERO="$local_dir/$dirname/-atload-"; local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && builtin eval "${ZINIT_ICE[atload]}"; ((1)); } || eval "${ZINIT_ICE[atload]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atload <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" atload + done + + (( ${+ZINIT_ICE[notify]} == 1 )) && { [[ $retval -eq 0 || -n ${(M)ZINIT_ICE[notify]#\!} ]] && { local msg; eval "msg=\"${ZINIT_ICE[notify]#\!}\""; .zinit-deploy-message @msg "$msg" } || .zinit-deploy-message @msg "notify: Plugin not loaded / loaded with problem, the return code: $retval"; } + (( ${+ZINIT_ICE[reset-prompt]} == 1 )) && .zinit-deploy-message @rst + + ZINIT[CUR_USPL2]= + ZINIT[TIME_INDEX]=$(( ${ZINIT[TIME_INDEX]:-0} + 1 )) + ZINIT[TIME_${ZINIT[TIME_INDEX]}_${id_as}]=$SECONDS + ZINIT[AT_TIME_${ZINIT[TIME_INDEX]}_${id_as}]=$EPOCHREALTIME + return $retval +} # >>> +# FUNCTION: .zinit-compdef-replay <<< +# Runs gathered compdef calls. This allows to run `compinit' +# after loading plugins. +.zinit-compdef-replay() { + local quiet="$1" + typeset -a pos + + # Check if compinit was loaded + if [[ ${+functions[compdef]} = 0 ]]; then + print "Compinit isn't loaded, cannot do compdef replay" + return 1 + fi + + # In the same order + local cdf + for cdf in "${ZINIT_COMPDEF_REPLAY[@]}"; do + pos=( "${(z)cdf}" ) + # When ZINIT_COMPDEF_REPLAY empty (also when only white spaces) + [[ ${#pos[@]} = 1 && -z ${pos[-1]} ]] && continue + pos=( "${(Q)pos[@]}" ) + [[ $quiet = -q ]] || print "Running compdef ${pos[*]}" + compdef "${pos[@]}" + done + + return 0 +} # >>> +# FUNCTION: .zinit-compdef-clear <<< +# Implements user-exposed functionality to clear gathered compdefs. +.zinit-compdef-clear() { + local quiet="$1" count="${#ZINIT_COMPDEF_REPLAY}" + ZINIT_COMPDEF_REPLAY=( ) + [[ $quiet = -q ]] || print "Compdef-replay cleared (had $count entries)" +} # >>> +# FUNCTION: .zinit-add-report <<< +# Adds a report line for given plugin. +# +# $1 - uspl2, i.e. user/plugin +# $2, ... - the text +.zinit-add-report() { + # Use zinit binary module if available + [[ -n $1 ]] && { (( ${+builtins[zpmod]} )) && zpmod report-append "$1" "$2"$'\n' || ZINIT_REPORTS[$1]+="$2"$'\n'; } + [[ ${ZINIT[DTRACE]} = 1 ]] && { (( ${+builtins[zpmod]} )) && zpmod report-append _dtrace/_dtrace "$2"$'\n' || ZINIT_REPORTS[_dtrace/_dtrace]+="$2"$'\n'; } + return 0 +} # >>> +# FUNCTION: .zinit-load-plugin <<< +# Lower-level function for loading a plugin. +# +# $1 - user +# $2 - plugin +# $3 - mode (light or load) +.zinit-load-plugin() { + local user="$1" plugin="$2" id_as="$3" mode="$4" correct=0 retval=0 + ZINIT[CUR_USR]="$user" ZINIT_CUR_PLUGIN="$plugin" ZINIT[CUR_USPL2]="$id_as" + [[ -o ksharrays ]] && correct=1 + + [[ -n ${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && \ + local -a precm=( + emulate + ${${(M)${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!}:+-R} + ${${ZINIT_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!} + ${${ZINIT_ICE[(i)(\!|)bash]}:+-${(s: :):-o noshglob -o braceexpand -o kshglob}} + -c + ) + + [[ ${ZINIT_ICE[as]} = null ]] && \ + ZINIT_ICE[pick]="${ZINIT_ICE[pick]:-/dev/null}" + + local pbase="${${plugin:t}%(.plugin.zsh|.zsh|.git)}" + [[ $user = % ]] && local pdir_path="$plugin" || local pdir_path="${ZINIT[PLUGINS_DIR]}/${id_as//\//---}" + local pdir_orig="$pdir_path" key + + if [[ ${ZINIT_ICE[as]} = command ]]; then + reply=() + if [[ -n ${ZINIT_ICE[pick]} && ${ZINIT_ICE[pick]} != /dev/null ]]; then + reply=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $pdir_path/${~ZINIT_ICE[pick]}(DN) ) + [[ -n ${reply[1-correct]} ]] && pdir_path="${reply[1-correct]:h}" + fi + [[ -z ${path[(er)$pdir_path]} ]] && { + [[ $mode != light ]] && .zinit-diff-env "${ZINIT[CUR_USPL2]}" begin + path=( "${pdir_path%/}" ${path[@]} ) + [[ $mode != light ]] && .zinit-diff-env "${ZINIT[CUR_USPL2]}" end + .zinit-add-report "${ZINIT[CUR_USPL2]}" "$ZINIT[col-info2]$pdir_path$ZINIT[col-rst] added to \$PATH" + } + [[ -n ${reply[1-correct]} && ! -x "${reply[1-correct]}" ]] && command chmod a+x ${reply[@]} + + [[ -n ${ZINIT_ICE[src]} || -n ${ZINIT_ICE[multisrc]} || ${ZINIT_ICE[atload][1]} = "!" ]] && { + if [[ ${ZINIT[SHADOWING]} = inactive ]]; then + (( ${+functions[compdef]} )) && ZINIT[bkp-compdef]="${functions[compdef]}" || builtin unset "ZINIT[bkp-compdef]" + functions[compdef]=':zinit-shadow-compdef "$@";' + ZINIT[SHADOWING]=1 + else + (( ++ ZINIT[SHADOWING] )) + fi + } + + local ZERO + [[ -n ${ZINIT_ICE[src]} ]] && { ZERO="${${(M)ZINIT_ICE[src]##/*}:-$pdir_orig/${ZINIT_ICE[src]}}"; (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; } + [[ -n ${ZINIT_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; }; eval "reply=(${ZINIT_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$pdir_orig/$fname}"; (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; done; } + + # Run the atload hooks right before atload ice + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atload <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" plugin "$user" "$plugin" "$id_as" "$pdir_orig" \!atload + done + + # Run the functions' wrapping & tracking requests + [[ -n ${ZINIT_ICE[wrap-track]} ]] && \ + .zinit-wrap-track-functions "$user" "$plugin" "$id_as" + + [[ ${ZINIT_ICE[atload][1]} = "!" ]] && { .zinit-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$pdir_orig/-atload-"; local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; } && builtin eval "${ZINIT_ICE[atload]#\!}"; } || eval "{ZINIT_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + + [[ -n ${ZINIT_ICE[src]} || -n ${ZINIT_ICE[multisrc]} || ${ZINIT_ICE[atload][1]} = "!" ]] && { + (( -- ZINIT[SHADOWING] == 0 )) && { ZINIT[SHADOWING]=inactive; builtin setopt noaliases; (( ${+ZINIT[bkp-compdef]} )) && functions[compdef]="${ZINIT[bkp-compdef]}" || unfunction compdef; builtin setopt aliases; } + } + elif [[ ${ZINIT_ICE[as]} = completion ]]; then + ((1)) + else + if [[ -n ${ZINIT_ICE[pick]} ]]; then + [[ ${ZINIT_ICE[pick]} = /dev/null ]] && reply=( /dev/null ) || reply=( ${(M)~ZINIT_ICE[pick]##/*}(DN) $pdir_path/${~ZINIT_ICE[pick]}(DN) ) + elif [[ -e $pdir_path/${pbase}.plugin.zsh ]]; then + reply=( "$pdir_path/${pbase}.plugin.zsh" ) + else + # The common file to source isn't there, so: + .zinit-find-other-matches "$pdir_path" "$pbase" + fi + + #[[ ${#reply} -eq 0 ]] && return 1 + + # Get first one + local fname="${reply[1-correct]:t}" + pdir_path="${reply[1-correct]:h}" + + .zinit-add-report "${ZINIT[CUR_USPL2]}" "Source $fname ${${${(M)mode:#light}:+(no reporting)}:-$ZINIT[col-info2](reporting enabled)$ZINIT[col-rst]}" + + # Light and compdef mode doesn't do diffs and shadowing + [[ $mode != (light|light-b) ]] && .zinit-diff "${ZINIT[CUR_USPL2]}" begin + + .zinit-shadow-on "${mode:-load}" + + # We need some state, but user wants his for his plugins + (( ${+ZINIT_ICE[blockf]} )) && { local -a fpath_bkp; fpath_bkp=( "${fpath[@]}" ); } + local ZERO="$pdir_path/$fname" + (( ${+ZINIT_ICE[aliases]} )) || builtin setopt noaliases + (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } + [[ -n ${ZINIT_ICE[src]} ]] && { ZERO="${${(M)ZINIT_ICE[src]##/*}:-$pdir_orig/${ZINIT_ICE[src]}}"; (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; } + [[ -n ${ZINIT_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; }; eval "reply=(${ZINIT_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$pdir_orig/$fname}"; (( ${+ZINIT_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } done; } + + # Run the atload hooks right before atload ice + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:\\\!atload <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" plugin "$user" "$plugin" "$id_as" "$pdir_orig" \!atload + done + + # Run the functions' wrapping & tracking requests + [[ -n ${ZINIT_ICE[wrap-track]} ]] && \ + .zinit-wrap-track-functions "$user" "$plugin" "$id_as" + + [[ ${ZINIT_ICE[atload][1]} = "!" ]] && { .zinit-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$pdir_orig/-atload-"; local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; } && builtin eval "${ZINIT_ICE[atload]#\!}"; ((1)); } || eval "${ZINIT_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + (( ${+ZINIT_ICE[aliases]} )) || builtin unsetopt noaliases + (( ${+ZINIT_ICE[blockf]} )) && { fpath=( "${fpath_bkp[@]}" ); } + + .zinit-shadow-off "${mode:-load}" + + [[ $mode != (light|light-b) ]] && .zinit-diff "${ZINIT[CUR_USPL2]}" end + fi + + [[ ${+ZINIT_ICE[atload]} = 1 && ${ZINIT_ICE[atload][1]} != "!" ]] && { ZERO="$pdir_orig/-atload-"; local __oldcd="$PWD"; (( ${+ZINIT_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; } && builtin eval "${ZINIT_ICE[atload]}"; ((1)); } || eval "${ZINIT_ICE[atload]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } + + reply=( "${(@on)ZINIT_EXTS[(I)z-annex hook:atload <->]}" ) + for key in "${reply[@]}"; do + arr=( "${(Q)${(z@)ZINIT_EXTS[$key]}[@]}" ) + "${arr[5]}" plugin "$user" "$plugin" "$id_as" "$pdir_orig" atload + done + + # Mark no load is in progress + ZINIT[CUR_USR]= ZINIT_CUR_PLUGIN= ZINIT[CUR_USPL2]= + + (( $5 )) && { print; zle .reset-prompt; } + return $retval +} # >>> +# FUNCTION: .zinit-add-fpath <<< +.zinit-add-fpath() { + [[ $1 = (-f|--front) ]] && { shift; integer front=1; } + .zinit-any-to-user-plugin "$1" "" + local id_as="$1" add_dir="$2" user="${reply[-2]}" plugin="${reply[-1]}" + (( front )) && \ + fpath[1,0]=${${${(M)user:#%}:+$plugin}:-${ZINIT[PLUGINS_DIR]}/${id_as//\//---}}${add_dir:+/$add_dir} || \ + fpath+=( + ${${${(M)user:#%}:+$plugin}:-${ZINIT[PLUGINS_DIR]}/${id_as//\//---}}${add_dir:+/$add_dir} + ) +} +# >>> +# FUNCTION: .zinit-run <<< +# Run code inside plugin's folder +# It uses the `correct' parameter from upper's scope zinit() +.zinit-run() { + if [[ $1 = (-l|--last) ]]; then + { set -- "${ZINIT[last-run-plugin]:-$(<${ZINIT[BIN_DIR]}/last-run-object.txt)}" "${@[2-correct,-1]}"; } &>/dev/null + [[ -z $1 ]] && { print "${ZINIT[col-error]}Error: No last plugin available, please specify as the first argument${ZINIT[col-rst]}"; return 1; } + else + integer __nolast=1 + fi + .zinit-any-to-user-plugin "$1" "" + local __id_as="$1" __user="${reply[-2]}" __plugin="${reply[-1]}" __oldpwd="$PWD" + () { + emulate -LR zsh + builtin cd &>/dev/null -q ${${${(M)__user:#%}:+$__plugin}:-${ZINIT[PLUGINS_DIR]}/${__id_as//\//---}} || { + local local_dir=${${__id_as%%\?*}/:\/\//--} + local_dir=${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--} + [[ -n $local_dir ]] && builtin cd &>/dev/null -q ${ZINIT[SNIPPETS_DIR]}/$local_dir + } + } + if (( $? == 0 )); then + (( __nolast )) && { print -r "$1" >! ${ZINIT[BIN_DIR]}/last-run-object.txt; } + ZINIT[last-run-plugin]="$1" + eval "${@[2-correct,-1]}" + () { setopt localoptions noautopushd; builtin cd -q "$__oldpwd"; } + else + print "${ZINIT[col-error]}Error: no such plugin or snippet${ZINIT[col-rst]}" + fi +} +# >>> + +# +# Dtrace +# + +# FUNCTION: .zinit-debug-start <<< +# Starts Dtrace, i.e. session tracking for changes in Zsh state. +.zinit-debug-start() { + if [[ ${ZINIT[DTRACE]} = 1 ]]; then + print "${ZINIT[col-error]}Dtrace is already active, stop it first with \`dstop'${ZINIT[col-rst]}" + return 1 + fi + + ZINIT[DTRACE]=1 + + .zinit-diff _dtrace/_dtrace begin + + # Full shadowing on + .zinit-shadow-on dtrace +} # >>> +# FUNCTION: .zinit-debug-stop <<< +# Stops Dtrace, i.e. session tracking for changes in Zsh state. +.zinit-debug-stop() { + ZINIT[DTRACE]=0 + + # Shadowing fully off + .zinit-shadow-off dtrace + + # Gather end data now, for diffing later + .zinit-diff _dtrace/_dtrace end +} # >>> +# FUNCTION: .zinit-clear-debug-report <<< +# Forgets dtrace repport gathered up to this moment. +.zinit-clear-debug-report() { + .zinit-clear-report-for _dtrace/_dtrace +} # >>> +# FUNCTION: .zinit-debug-unload <<< +# Reverts changes detected by dtrace run. +.zinit-debug-unload() { + if [[ ${ZINIT[DTRACE]} = 1 ]]; then + print "Dtrace is still active, end it with \`dstop'" + else + .zinit-unload _dtrace _dtrace + fi +} # >>> + +# +# Ice support +# + +# FUNCTION: .zinit-ice <<< +# Parses ICE specification (`zplg ice' subcommand), puts the result +# into ZINIT_ICE global hash. The ice-spec is valid for next command +# only (i.e. it "melts"), but it can then stick to plugin and activate +# e.g. at update. +.zinit-ice() { + builtin setopt localoptions noksharrays extendedglob warncreateglobal typesetsilent noshortloops + integer retval + local bit exts="${~ZINIT_EXTS[ice-mods]//\'\'/}" + for bit; do + [[ $bit = (#b)(--|)(teleid|from|proto|cloneopts|depth|wait|load|\ +unload|on-update-of|subscribe|if|has|cloneonly|nocloneonly|blockf|\ +svn|nosvn|pick|nopick|src|bpick|as|ver|silent|lucid|mv|cp|atinit|\ +atload|atpull|atclone|run-atpull|norun-atpull|make|nomake|notify|\ +nonotify|reset-prompt|service|compile|nocompile|nocompletions|multisrc|\ +id-as|bindmap|trackbinds|notrackbinds|nocd|once|wrap-track|reset|\ +noreset|sh|\!sh|bash|\!bash|ksh|\!ksh|csh|\!csh|aliases|noaliases|\ +countdown|nocountdown|trigger-load|light-mode|is-snippet|pack|\ +atdelete|git|verbose|param${~exts})(*) + ]] && \ + ZINIT_ICES[${match[2]}]+="${ZINIT_ICES[${match[2]}]:+;}${match[3]#(:|=)}" || \ + break + retval+=1 + done + [[ ${ZINIT_ICES[as]} = program ]] && ZINIT_ICES[as]=command + [[ -n ${ZINIT_ICES[on-update-of]} ]] && ZINIT_ICES[subscribe]="${ZINIT_ICES[subscribe]:-${ZINIT_ICES[on-update-of]}}" + [[ -n ${ZINIT_ICES[pick]} ]] && ZINIT_ICES[pick]="${ZINIT_ICES[pick]//\$ZPFX/${ZPFX%/}}" + return $retval +} # >>> +# FUNCTION: .zinit-pack-ice <<< +# Remembers all ice-mods, assigns them to concrete plugin. Ice spec +# is in general forgotten for second-next command (that's why it's +# called "ice" - it melts), however they glue to the object (plugin +# or snippet) mentioned in the next command – for later use with e.g. +# `zinit update ...' +.zinit-pack-ice() { + ZINIT_SICE[$1${1:+${2:+/}}$2]+="${(j: :)${(qkv)ZINIT_ICE[@]}} " + ZINIT_SICE[$1${1:+${2:+/}}$2]="${ZINIT_SICE[$1${1:+${2:+/}}$2]# }" + return 0 +} # >>> +# FUNCTION: .zinit-service <<< +# Handles given service, i.e. obtains lock, runs it, or waits if no lock +# +# $1 - type "p" or "s" (plugin or snippet) +# $2 - mode - for plugin (light or load) +# $3 - id - URL or plugin ID or alias name (from id-as'') +.zinit-service() { + local __tpe="$1" __mode="$2" __id="$3" __fle="${ZINIT[SERVICES_DIR]}/${ZINIT_ICE[service]}.lock" __fd __cmd __tmp __lckd __strd=0 + { builtin print -n >! "$__fle"; } 2>/dev/null 1>&2 + [[ ! -e ${__fle:r}.fifo ]] && command mkfifo "${__fle:r}.fifo" 2>/dev/null 1>&2 + [[ ! -e ${__fle:r}.fifo2 ]] && command mkfifo "${__fle:r}.fifo2" 2>/dev/null 1>&2 + + typeset -g ZSRV_WORK_DIR="${ZINIT[SERVICES_DIR]}" ZSRV_ID="${ZINIT_ICE[service]}" # should be also set by other p-m + + while (( 1 )); do + ( + while (( 1 )); do + [[ ! -f ${__fle:r}.stop ]] && if (( __lckd )) || zsystem 2>/dev/null 1>&2 flock -t 1 -f __fd -e $__fle; then + __lckd=1 + if (( ! __strd )) || [[ $__cmd = RESTART ]]; then + [[ $__tpe = p ]] && { __strd=1; .zinit-load "$__id" "" "$__mode"; } + [[ $__tpe = s ]] && { __strd=1; .zinit-load-snippet "$__id" ""; } + fi + __cmd= + while (( 1 )); do builtin read -t 32767 __cmd <>"${__fle:r}.fifo" && break; done + else + return 0 + fi + + [[ $__cmd = (#i)NEXT ]] && { kill -TERM "$ZSRV_PID"; builtin read -t 2 __tmp <>"${__fle:r}.fifo2"; kill -HUP "$ZSRV_PID"; exec {__fd}>&-; __lckd=0; __strd=0; builtin read -t 10 __tmp <>"${__fle:r}.fifo2"; } + [[ $__cmd = (#i)STOP ]] && { kill -TERM "$ZSRV_PID"; builtin read -t 2 __tmp <>"${__fle:r}.fifo2"; kill -HUP "$ZSRV_PID"; __strd=0; builtin print >! "${__fle:r}.stop"; } + [[ $__cmd = (#i)QUIT ]] && { kill -HUP ${sysparams[pid]}; return 1; } + [[ $__cmd != (#i)RESTART ]] && { __cmd=; builtin read -t 1 __tmp <>"${__fle:r}.fifo2"; } + done + ) || break + builtin read -t 1 __tmp <>"${__fle:r}.fifo2" + done >>! "$ZSRV_WORK_DIR/$ZSRV_ID".log 2>&1 +} +# >>> +# FUNCTION: .zinit-run-task <<< +# A backend, worker function of .zinit-scheduler. It obtains the tasks +# index and a few of its properties (like the type: plugin, snippet, +# service plugin, service snippet) and executes it first checking for +# additional conditions (like non-numeric wait'' ice). +# +# $1 - the pass number, either 1st or 2nd pass +# $2 - the time assigned to the task +# $3 - type: plugin, snippet, service plugin, service snippet +# $4 - task's index in the ZINIT[WAIT_ICE_...] fields +# $5 - mode: load or light +# $6 - the plugin-spec or snippet URL or alias name (from id-as'') +.zinit-run-task() { + local __pass="$1" __t="$2" __tpe="$3" __idx="$4" __mode="$5" __id="${(Q)6}" __opt="${(Q)7}" __action __s=1 __retval=0 + + local -A ZINIT_ICE + ZINIT_ICE=( "${(@Q)${(z@)ZINIT[WAIT_ICE_${__idx}]}}" ) + + local __id_as=${ZINIT_ICE[id-as]:-$__id} + + if [[ $__pass = 1 && ${${ZINIT_ICE[wait]#\!}%%[^0-9]([^0-9]|)([^0-9]|)([^0-9]|)} = <-> ]]; then + __action="${(M)ZINIT_ICE[wait]#\!}load" + elif [[ $__pass = 1 && -n ${ZINIT_ICE[wait]#\!} ]] && { eval "${ZINIT_ICE[wait]#\!}" || [[ $(( __s=0 )) = 1 ]]; }; then + __action="${(M)ZINIT_ICE[wait]#\!}load" + elif [[ -n ${ZINIT_ICE[load]#\!} && -n $(( __s=0 )) && $__pass = 3 && -z ${ZINIT_REGISTERED_PLUGINS[(r)$__id_as]} ]] && eval "${ZINIT_ICE[load]#\!}"; then + __action="${(M)ZINIT_ICE[load]#\!}load" + elif [[ -n ${ZINIT_ICE[unload]#\!} && -n $(( __s=0 )) && $__pass = 2 && -n ${ZINIT_REGISTERED_PLUGINS[(r)$__id_as]} ]] && eval "${ZINIT_ICE[unload]#\!}"; then + __action="${(M)ZINIT_ICE[unload]#\!}remove" + elif [[ -n ${ZINIT_ICE[subscribe]#\!} && -n $(( __s=0 )) && $__pass = 3 ]] && \ + { local -a fts_arr + eval "fts_arr=( ${ZINIT_ICE[subscribe]}(DNms-$(( EPOCHSECONDS - + ZINIT[fts-${ZINIT_ICE[subscribe]}] ))) ); (( \${#fts_arr} ))" && \ + { ZINIT[fts-${ZINIT_ICE[subscribe]}]="$EPOCHSECONDS"; __s=${+ZINIT_ICE[once]}; } || \ + (( 0 )) + } + then + __action="${(M)ZINIT_ICE[subscribe]#\!}load" + fi + + if [[ $__action = *load ]]; then + if [[ $__tpe = p ]]; then + .zinit-load "$__id" "" "$__mode"; (( __retval += $? )) + elif [[ $__tpe = s ]]; then + .zinit-load-snippet $__opt "${(@)=__id}"; (( __retval += $? )) + elif [[ $__tpe = p1 || $__tpe = s1 ]]; then + zpty -b "${__id//\//:} / ${ZINIT_ICE[service]}" '.zinit-service '"${(M)__tpe#?}"' "$__mode" "$__id"' + fi + (( ${+ZINIT_ICE[silent]} == 0 && ${+ZINIT_ICE[lucid]} == 0 && __retval == 0 )) && zle && zle -M "Loaded $__id" + elif [[ $__action = *remove ]]; then + (( ${+functions[.zinit-confirm]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-autoload.zsh + [[ $__tpe = p ]] && .zinit-unload "$__id_as" "" -q + (( ${+ZINIT_ICE[silent]} == 0 && ${+ZINIT_ICE[lucid]} == 0 && __retval == 0 )) && zle && zle -M "Unloaded $__id_as" + fi + + [[ ${REPLY::=$__action} = \!* ]] && zle && zle .reset-prompt + + return $__s +} +# >>> +# FUNCTION: .zinit-deploy-message <<< +# Deploys a sub-prompt message to be displayed OR a `zle +# .reset-prompt' call to be invoked +.zinit-deploy-message() { + [[ $1 = <-> && ( ${#} = 1 || ( $2 = (hup|nval|err) && ${#} = 2 ) ) ]] && { zle && { + local alltext text IFS=$'\n' nl=$'\n' + repeat 25; do read -r -u"$1" text; alltext+="${text:+$text$nl}"; done + [[ $alltext = @rst$nl ]] && { builtin zle reset-prompt; ((1)); } || \ + { [[ -n $alltext ]] && builtin zle -M "$alltext"; } + } + builtin zle -F "$1"; exec {1}<&- + return 0 + } + local THEFD=13371337 hasw + # The expansion is: if there is @sleep: pfx, then use what's after + # it, otherwise substitute 0 + exec {THEFD} < <(LANG=C sleep $(( 0.01 + ${${${(M)1#@sleep:}:+${1#@sleep:}}:-0} )); print -r -- ${1:#(@msg|@sleep:*)} "${@[2,-1]}"; ) + command true # workaround a Zsh bug, see: http://www.zsh.org/mla/workers/2018/msg00966.html + builtin zle -F "$THEFD" .zinit-deploy-message +} +# >>> + +# FUNCTION: .zinit-submit-turbo <<< +# If `zinit load`, `zinit light` or `zinit snippet` will be +# preceded with `wait', `load', `unload' or `on-update-of`/`subscribe' +# ice-mods then the plugin or snipped is to be loaded in turbo-mode, +# and this function adds it to internal data structures, so that +# @zinit-scheduler can run (load, unload) this as a task. +.zinit-submit-turbo() { + local tpe="$1" mode="$2" opt_uspl2="$3" opt_plugin="$4" + + ZINIT_ICE[wait]="${ZINIT_ICE[wait]%%.[0-9]##}" + ZINIT[WAIT_IDX]=$(( ${ZINIT[WAIT_IDX]:-0} + 1 )) + ZINIT[WAIT_ICE_${ZINIT[WAIT_IDX]}]="${(j: :)${(qkv)ZINIT_ICE[@]}}" + ZINIT[fts-${ZINIT_ICE[subscribe]}]="${ZINIT_ICE[subscribe]:+$EPOCHSECONDS}" + + [[ $tpe = s* ]] && \ + local id="${${opt_plugin:+$opt_plugin}:-$opt_uspl2}" || \ + local id="${${opt_plugin:+$opt_uspl2${${opt_uspl2:#%*}:+/}$opt_plugin}:-$opt_uspl2}" + + if [[ ${${ZINIT_ICE[wait]}%%[^0-9]([^0-9]|)([^0-9]|)([^0-9]|)} = (\!|.|)<-> ]]; then + ZINIT_TASKS+=( "$EPOCHSECONDS+${${ZINIT_ICE[wait]#(\!|.)}%%[^0-9]([^0-9]|)([^0-9]|)([^0-9]|)}+${${${(M)ZINIT_ICE[wait]%a}:+1}:-${${${(M)ZINIT_ICE[wait]%b}:+2}:-${${${(M)ZINIT_ICE[wait]%c}:+3}:-1}}} $tpe ${ZINIT[WAIT_IDX]} ${mode:-_} ${(q)id} ${opt_plugin:+${(q)opt_uspl2}}" ) + elif [[ -n ${ZINIT_ICE[wait]}${ZINIT_ICE[load]}${ZINIT_ICE[unload]}${ZINIT_ICE[subscribe]} ]]; then + ZINIT_TASKS+=( "${${ZINIT_ICE[wait]:+0}:-1}+0+1 $tpe ${ZINIT[WAIT_IDX]} ${mode:-_} ${(q)id} ${opt_plugin:+${(q)opt_uspl2}}" ) + fi +} +# >>> +# FUNCTION: -zinit_scheduler_add_sh <<< +# Copies task into ZINIT_RUN array, called when a task timeouts. +# A small function ran from pattern in /-substitution as a math +# function. +-zinit_scheduler_add_sh() { + local idx="$1" in_wait="$__ar2" in_abc="$__ar3" ver_wait="$__ar4" ver_abc="$__ar5" + if [[ ( $in_wait = $ver_wait || $in_wait -ge 4 ) && $in_abc = $ver_abc ]]; then + ZINIT_RUN+=( "${ZINIT_TASKS[$idx]}" ) + return 1 + else + return $idx + fi +} +# >>> +# FUNCTION: @zinit-scheduler <<< +# Searches for timeout tasks, executes them. There's an array of tasks +# waiting for execution, this scheduler manages them, detects which ones +# should be run at current moment, decides to remove (or not) them from +# the array after execution. +# +# $1 - if "following", then it is non-first (second and more) +# invocation of the scheduler; this results in chain of `sched' +# invocations that results in repetitive @zinit-scheduler activity +# +# if "burst", then all tasks are marked timeout and executed one +# by one; this is handy if e.g. a docker image starts up and +# needs to install all turbo-mode plugins without any hesitation +# (delay), i.e. "burst" allows to run package installations from +# script, not from prompt +# +@zinit-scheduler() { + integer __ret="${${ZINIT[lro-data]%:*}##*:}" + # lro stands for lastarg-retval-option + [[ $1 = following ]] && sched +1 'ZINIT[lro-data]="$_:$?:${options[printexitvalue]}"; @zinit-scheduler following "${ZINIT[lro-data]%:*:*}"' + [[ -n $1 && $1 != (following*|burst) ]] && { local THEFD="$1"; zle -F "$THEFD"; exec {THEFD}<&-; } + [[ $1 = burst ]] && local -h EPOCHSECONDS=$(( EPOCHSECONDS+10000 )) + ZINIT[START_TIME]="${ZINIT[START_TIME]:-$EPOCHREALTIME}" + + integer __t=EPOCHSECONDS __i correct=0 + local -a match mbegin mend reply + local REPLY ANFD + + [[ -o ksharrays ]] && correct=1 + + [[ -n $1 ]] && { + () { + builtin emulate -L zsh + builtin setopt extendedglob + # Example entry: + # 1531252764+2+1 p 18 light zdharma/zsh-diff-so-fancy + # + # This either doesn't change ZINIT_TASKS entry - when + # __i is used in the ternary expression, or replaces + # an entry with "", i.e. ZINIT_TASKS[1] entry. + integer __idx1 __idx2 + local __ar2 __ar3 __ar4 __ar5 + for (( __idx1 = 0; __idx1 <= 4; __idx1 ++ )); do + for (( __idx2 = 1; __idx2 <= (__idx >= 4 ? 1 : 3); __idx2 ++ )); do + # The following substitution could be just (well, 'just'..) this: + # + # ZINIT_TASKS=( ${ZINIT_TASKS[@]/(#b)([0-9]##)+([0-9]##)+([1-3])(*)/ + # ${ZINIT_TASKS[$(( (${match[1]}+${match[2]}) <= $__t ? + # zinit_scheduler_add(__i++, ${match[2]}, + # ${(M)match[3]%[1-3]}, __idx1, __idx2) : __i++ ))]}} ) + # + # However, there's a severe bug in Zsh <= 5.3.1 - use of the period + # (,) is impossible inside ${..//$arr[$(( ... ))]}. + __i=2 + + ZINIT_TASKS=( ${ZINIT_TASKS[@]/(#b)([0-9]##)+([0-9]##)+([1-3])(*)/${ZINIT_TASKS[ + $(( (__ar2=${match[2]}+1) ? ( + (__ar3=${(M)match[3]%[1-3]}) ? ( + (__ar4=__idx1+1) ? ( + (__ar5=__idx2) ? ( + (${match[1]}+${match[2]}) <= $__t ? + zinit_scheduler_add(__i++) : __i++ ) + : 1 ) + : 1 ) + : 1 ) + : 1 ))]}} ) + ZINIT_TASKS=( "" ${ZINIT_TASKS[@]:#} ) + done + done + } + } || { + add-zsh-hook -d -- precmd @zinit-scheduler + add-zsh-hook -- chpwd @zinit-scheduler + () { + builtin emulate -L zsh + builtin setopt extendedglob + # No "+" in this pattern, it will match only "1531252764" + # in "1531252764+2" and replace it with current time + ZINIT_TASKS=( ${ZINIT_TASKS[@]/(#b)([0-9]##)(*)/$(( ${match[1]} <= 1 ? ${match[1]} : __t ))${match[2]}} ) + } + # There's a bug in Zsh: first sched call would not be issued + # until a key-press, if "sched +1 ..." would be called inside + # zle -F handler. So it's done here, in precmd-handle code. + sched +1 'ZINIT[lro-data]="$_:$?:${options[printexitvalue]}"; @zinit-scheduler following ${ZINIT[lro-data]%:*:*}' + + ANFD=13371337 # for older Zsh + noclobber option + exec {ANFD}< <(LANG=C command sleep 0.002; builtin print run;) + command true # workaround a Zsh bug, see: http://www.zsh.org/mla/workers/2018/msg00966.html + zle -F "$ANFD" @zinit-scheduler + } + + local __task __idx=0 __count=0 __idx2 + # All wait'' objects + for __task in "${ZINIT_RUN[@]}"; do + .zinit-run-task 1 "${(@z)__task}" && ZINIT_TASKS+=( "$__task" ) + [[ $(( ++__idx, __count += ${${REPLY:+1}:-0} )) -gt 0 && $1 != burst ]] && \ + { + ANFD=13371337 # for older Zsh + noclobber option + exec {ANFD}< <(LANG=C command sleep 0.0002; builtin print run;) + command true # workaround a Zsh bug, see: http://www.zsh.org/mla/workers/2018/msg00966.html + # The $? and $_ will be preserved automatically by Zsh + # – that's how calling the -F handler is implemented + zle -F "$ANFD" @zinit-scheduler + break + } + done + # All unload'' objects + for (( __idx2=1; __idx2 <= __idx; ++ __idx2 )); do + .zinit-run-task 2 "${(@z)ZINIT_RUN[__idx2-correct]}" + done + # All load'' & subscribe'' objects + for (( __idx2=1; __idx2 <= __idx; ++ __idx2 )); do + .zinit-run-task 3 "${(@z)ZINIT_RUN[__idx2-correct]}" + done + ZINIT_RUN[1-correct,__idx-correct]=() + + [[ ${ZINIT[lro-data]##*:} = on ]] && return 0 || return $__ret +} +# >>> + +# +# Exposed functions +# + +# FUNCTION: zinit <<< +# Main function directly exposed to user, obtains subcommand and its +# arguments, has completion. +zinit() { + local -A ZINIT_ICE + ZINIT_ICE=( "${(kv)ZINIT_ICES[@]}" ) + ZINIT_ICES=() + + integer retval=0 correct=0 + local -a match mbegin mend reply + local MATCH REPLY; integer MBEGIN MEND + + [[ -o ksharrays ]] && correct=1 + + local -A opt_map ICE_OPTS + opt_map=( + -q opt_-q,--quiet + --quiet opt_-q,--quiet + -r opt_-r,--reset + --reset opt_-r,--reset + --all opt_--all + --clean opt_--clean + --yes opt_-y,--yes + -y opt_-y,--yes + -f opt_-f,--force + --force opt_-f,--force + ) + + [[ $1 != (-h|--help|help|man|self-update|times|zstatus|load|light|unload|snippet|ls|ice|\ +update|status|report|delete|loaded|list|cd|create|edit|glance|stress|changes|recently|clist|\ +completions|cclear|cdisable|cenable|creinstall|cuninstall|csearch|compinit|dtrace|dstart|dstop|\ +dunload|dreport|dclear|compile|uncompile|compiled|cdlist|cdreplay|cdclear|srv|recall|\ +env-whitelist|bindkeys|module|add-fpath|fpath|run) || $1 = (load|light|snippet) ]] && \ + { + integer __is_snippet + if [[ $1 = (load|light|snippet) ]]; then + # Classic syntax -> simulate a call through the for-syntax + () { + setopt localoptions extendedglob + : ${@[@]//(#b)([ $'\t']##|(#s))(-b|--command|-f)([ $'\t']##|(#e))/${ICE_OPTS[${match[2]}]::=1}} + } "$@" + set -- "${@[@]:#(-b|--command|-f)}" + [[ $1 = light && -z ${ICE_OPTS[(I)-b]} ]] && ZINIT_ICE[light-mode]= + [[ $1 = snippet ]] && ZINIT_ICE[is-snippet]= || __is_snippet=-1 + shift + + ZINIT_ICES=( "${(kv)ZINIT_ICE[@]}" ) + ZINIT_ICE=() + 1="${1:+@}${1#@}${2:+/$2}" + (( $# > 1 )) && { shift -p $(( $# - 1 )); } + [[ -z $1 ]] && { + print "Argument needed, try: help" + return 1 + } + else + .zinit-ice "$@" + shift $? + if [[ $# -gt 0 && $1 != for ]]; then + print "Unknown command or ice: \`$1' (use \`help' to get usage information)" + return 1 + fi + [[ $1 = for ]] && shift + fi + integer __retval __had_wait + if (( $# )); then + local -a __ices + __ices=( "${(kv)ZINIT_ICES[@]}" ) + ZINIT_ICES=() + while (( $# )) { + .zinit-ice "$@" + shift $? + [[ -z ${ZINIT_ICES[subscribe]} ]] && unset 'ZINIT_ICES[subscribe]' + if [[ -n $1 ]]; then + ZINIT_ICE=( "${__ices[@]}" "${(kv)ZINIT_ICES[@]}" ) + ZINIT_ICES=() + + (( ${+ZINIT_ICE[pack]} )) && { + __had_wait=${+ZINIT_ICE[wait]} + .zinit-load-ices "${1#@}" + [[ -z ${ZINIT_ICE[wait]} && $__had_wait == 0 ]] && \ + unset 'ZINIT_ICE[wait]' + } + + [[ ${ZINIT_ICE[id-as]} = auto ]] && ZINIT_ICE[id-as]="${1:t}" + + [[ $__is_snippet -ge 0 ]] && { + [[ -n ${ZINIT_ICE[is-snippet]+1} || + ${1#@} = ((#i)(http(s|)|ftp(s|)):/|((OMZ|PZT)::))* + ]] && \ + __is_snippet=1 || \ + __is_snippet=0 + } + + if [[ -n ${ZINIT_ICE[trigger-load]} ]] { + () { + setopt localoptions extendedglob + local mode + (( __is_snippet > 0 )) && mode=snippet || mode="${${${ZINIT_ICE[light-mode]+light}}:-load}" + for MATCH ( ${(s.;.)ZINIT_ICE[trigger-load]} ) { + eval "${MATCH#!}() { + ${${(M)MATCH#!}:+unset -f ${MATCH#!}} + local a b; local -a ices + # The wait'' ice is filtered-out + for a b ( ${(qqkv@)${(kv@)ZINIT_ICE[(I)^(trigger-load|wait|light-mode)]}} ) { + ices+=( \"\$a\$b\" ) + } + zinit ice \${ices[@]}; zinit $mode ${(qqq)${1#@}} + ${${(M)MATCH#!}:+# Forward the call + eval ${MATCH#!} \$@} + }" + } + } "$@" + __retval+=$? + (( $# )) && shift + continue + } + + (( ${+ZINIT_ICE[if]} )) && { eval "${ZINIT_ICE[if]}" || { (( $# )) && shift; continue; }; } + (( ${+ZINIT_ICE[has]} )) && { (( ${+commands[${ZINIT_ICE[has]}]} )) || { (( $# )) && shift; continue; }; } + + ZINIT_ICE[wait]="${${(M)${+ZINIT_ICE[wait]}:#1}:+${(M)ZINIT_ICE[wait]#!}${${ZINIT_ICE[wait]#!}:-0}}" + if [[ -n ${ZINIT_ICE[wait]}${ZINIT_ICE[load]}${ZINIT_ICE[unload]}${ZINIT_ICE[service]}${ZINIT_ICE[subscribe]} ]]; then + ZINIT_ICE[wait]="${ZINIT_ICE[wait]:-${ZINIT_ICE[service]:+0}}" + if (( __is_snippet > 0 )); then + ZINIT_SICE[${${1#@}%%(/|//|///)}]= + .zinit-submit-turbo s${ZINIT_ICE[service]:+1} "" \ + "${${1#@}%%(/|//|///)}" \ + "${(k)ICE_OPTS[*]}" + else + ZINIT_SICE[${${${1#@}#https://github.com/}%%(/|//|///)}]= + .zinit-submit-turbo p${ZINIT_ICE[service]:+1} \ + "${${${ZINIT_ICE[light-mode]+light}}:-load}" \ + "${${${1#@}#https://github.com/}%%(/|//|///)}" "" + fi + __retval+=$? + else + if (( __is_snippet > 0 )); then + .zinit-load-snippet ${(k)ICE_OPTS[@]} "${${1#@}%%(/|//|///)}" + else + .zinit-load "${${${1#@}#https://github.com/}%%(/|//|///)}" "" \ + "${${ZINIT_ICE[light-mode]+light}:-${ICE_OPTS[(I)-b]:+light-b}}" + fi + __retval+=$? + fi + fi + (( $# )) && shift + } + fi + return __retval + } + + case "$1" in + (ice) + shift + .zinit-ice "$@" + ;; + (cdreplay) + .zinit-compdef-replay "$2"; retval=$? + ;; + (cdclear) + .zinit-compdef-clear "$2" + ;; + (add-fpath|fpath) + .zinit-add-fpath "${@[2-correct,-1]}" + ;; + (run) + .zinit-run "${@[2-correct,-1]}" + ;; + (dstart|dtrace) + .zinit-debug-start + ;; + (dstop) + .zinit-debug-stop + ;; + (man) + man "${ZINIT[BIN_DIR]}/doc/zinit.1" + ;; + (env-whitelist) + shift + [[ $1 = -v ]] && { shift; local verbose=1; } + [[ $1 = -h ]] && { shift; print "Usage: zinit env-whitelist [-v] VAR1 ...\nSaves names (also patterns) of parameters left unchanged during an unload. -v - verbose."; } + (( $# == 0 )) && { + ZINIT[ENV-WHITELIST]= + (( verbose )) && print "Cleared parameter whitelist" + } || { + ZINIT[ENV-WHITELIST]+="${(j: :)${(q-kv)@}} " + (( verbose )) && print "Extended parameter whitelist" + } + ;; + (*) + # Check if there is a z-annex registered for the subcommand + reply=( ${ZINIT_EXTS[z-annex subcommand:${(q)1}]} ) + (( ${#reply} )) && { + reply=( "${(Q)${(z@)reply[1]}[@]}" ) + (( ${+functions[${reply[5]}]} )) && { "${reply[5]}" "$@"; return $?; } || + { print -r -- "(Couldn't find the subcommand-handler \`${reply[5]}' of the z-annex \`${reply[3]}')"; return 1; } + } + (( ${+functions[.zinit-confirm]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-autoload.zsh + case "$1" in + (zstatus) + .zinit-show-zstatus + ;; + (times) + .zinit-show-times "${@[2-correct,-1]}" + ;; + (self-update) + .zinit-self-update + ;; + (unload) + (( ${+functions[.zinit-unload]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-autoload.zsh + if [[ -z $2 && -z $3 ]]; then + print "Argument needed, try: help"; retval=1 + else + [[ $2 = -q ]] && { 5=-q; shift; } + # Unload given plugin. Cloned directory remains intact + # so as are completions + .zinit-unload "${2%%(/|//|///)}" "${${3:#-q}%%(/|//|///)}" "${${(M)4:#-q}:-${(M)3:#-q}}"; retval=$? + fi + ;; + (bindkeys) + .zinit-list-bindkeys + ;; + (update) + (( ${+ZINIT_ICE[if]} )) && { eval "${ZINIT_ICE[if]}" || return 1; } + (( ${+ZINIT_ICE[has]} )) && { (( ${+commands[${ZINIT_ICE[has]}]} )) || return 1; } + () { + setopt localoptions extendedglob + : ${@[@]//(#b)([ $'\t']##|(#s))(-q|--quiet|-r|--reset|-f|--force)([ $'\t']##|(#e))/${ICE_OPTS[${opt_map[${match[2]}]}]::=1}} + } "$@" + set -- "${@[@]:#(--quiet|-q|--reset|-r|-f|--force)}" + if [[ $2 = --all || ( -z $2 && -z $3 && -z ${ZINIT_ICE[teleid]} && -z ${ZINIT_ICE[id-as]} ) ]]; then + [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } + .zinit-update-or-status-all update; retval=$? + else + .zinit-update-or-status update "${${2%%(/|//|///)}:-${ZINIT_ICE[id-as]:-$ZINIT_ICE[teleid]}}" "${3%%(/|//|///)}"; retval=$? + fi + ;; + (status) + if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then + [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } + .zinit-update-or-status-all status; retval=$? + else + .zinit-update-or-status status "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? + fi + ;; + (report) + if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then + [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 3; } + .zinit-show-all-reports + else + .zinit-show-report "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? + fi + ;; + (loaded|list) + # Show list of loaded plugins + .zinit-show-registered-plugins "$2" + ;; + (clist|completions) + # Show installed, enabled or disabled, completions + # Detect stray and improper ones + .zinit-show-completions "$2" + ;; + (cclear) + # Delete stray and improper completions + .zinit-clear-completions + ;; + (cdisable) + if [[ -z $2 ]]; then + print "Argument needed, try: help"; retval=1 + else + local f="_${2#_}" + # Disable completion given by completion function name + # with or without leading _, e.g. cp, _cp + if .zinit-cdisable "$f"; then + (( ${+functions[.zinit-forget-completion]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + .zinit-forget-completion "$f" + print "Initializing completion system (compinit)..." + builtin autoload -Uz compinit + compinit -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}" + else + retval=1 + fi + fi + ;; + (cenable) + if [[ -z $2 ]]; then + print "Argument needed, try: help"; retval=1 + else + local f="_${2#_}" + # Enable completion given by completion function name + # with or without leading _, e.g. cp, _cp + if .zinit-cenable "$f"; then + (( ${+functions[.zinit-forget-completion]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + .zinit-forget-completion "$f" + print "Initializing completion system (compinit)..." + builtin autoload -Uz compinit + compinit -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}" + else + retval=1 + fi + fi + ;; + (creinstall) + (( ${+functions[.zinit-install-completions]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + # Installs completions for plugin. Enables them all. It's a + # reinstallation, thus every obstacle gets overwritten or removed + [[ $2 = -q ]] && { 5=-q; shift; } + .zinit-install-completions "${2%%(/|//|///)}" "${3%%(/|//|///)}" 1 "${(M)4:#-q}"; retval=$? + [[ -z ${(M)4:#-q} ]] && print "Initializing completion (compinit)..." + builtin autoload -Uz compinit + compinit -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}" + ;; + (cuninstall) + if [[ -z $2 && -z $3 ]]; then + print "Argument needed, try: help"; retval=1 + else + (( ${+functions[.zinit-forget-completion]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + # Uninstalls completions for plugin + .zinit-uninstall-completions "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? + print "Initializing completion (compinit)..." + builtin autoload -Uz compinit + compinit -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}" + fi + ;; + (csearch) + .zinit-search-completions + ;; + (compinit) + (( ${+functions[.zinit-forget-completion]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + .zinit-compinit; retval=$? + ;; + (dreport) + .zinit-show-debug-report + ;; + (dclear) + .zinit-clear-debug-report + ;; + (dunload) + .zinit-debug-unload + ;; + (compile) + (( ${+functions[.zinit-compile-plugin]} )) || builtin source ${ZINIT[BIN_DIR]}/zinit-install.zsh + if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then + [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } + .zinit-compile-uncompile-all 1; retval=$? + else + .zinit-compile-plugin "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? + fi + ;; + (uncompile) + if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then + [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } + .zinit-compile-uncompile-all 0; retval=$? + else + .zinit-uncompile-plugin "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? + fi + ;; + (compiled) + .zinit-compiled + ;; + (cdlist) + .zinit-list-compdef-replay + ;; + (cd|delete|recall|edit|glance|changes|create|stress) + .zinit-"$1" "${@[2-correct,-1]%%(/|//|///)}"; retval=$? + ;; + (recently) + shift + .zinit-recently "$@"; retval=$? + ;; + (-h|--help|help|"") + .zinit-help + ;; + (ls) + shift + .zinit-ls "$@" + ;; + (srv) + () { setopt localoptions extendedglob warncreateglobal + [[ ! -e ${ZINIT[SERVICES_DIR]}/"$2".fifo ]] && { print "No such service: $2"; } || + { [[ $3 = (#i)(next|stop|quit|restart) ]] && + { print "${(U)3}" >>! ${ZINIT[SERVICES_DIR]}/"$2".fifo || print "Service $2 inactive"; retval=1; } || + { [[ $3 = (#i)start ]] && rm -f ${ZINIT[SERVICES_DIR]}/"$2".stop || + { print "Unknown service-command: $3"; retval=1; } + } + } + } "$@" + ;; + (module) + .zinit-module "${@[2-correct,-1]}"; retval=$? + ;; + (*) + print "Unknown command \`$1' (use \`help' to get usage information)" + retval=1 + ;; + esac + ;; + esac + + return $retval +} # >>> +# FUNCTION: zicdreplay <<< +# A function that can be invoked from within `atinit', `atload', etc. +# ice-mod. It works like `zinit cdreplay', which cannot be invoked +# from such hook ices. +zicdreplay() { .zinit-compdef-replay -q; } +# >>> +# FUNCTION: zicdclear <<< +# A wrapper for `zinit cdclear -q' which can be called from hook +# ices like the atinit'', atload'', etc. ices. +zicdclear() { .zinit-compdef-clear -q; } +# >>> +# FUNCTION: zicompinit <<< +# A function that can be invoked from within `atinit', `atload', etc. +# ice-mod. It runs `autoload compinit; compinit' and respects +# ZINIT[ZCOMPDUMP_PATH] and ZINIT[COMPINIT_OPTS]. +zicompinit() { autoload -Uz compinit; compinit -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}"; } +# >>> +# FUNCTION: zicompdef <<< +# Stores compdef for a replay with `zicdreplay' (turbo mode) or +# with `zinit cdreplay' (normal mode). An utility functton of +# an undefined use case. +zicompdef() { ZINIT_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" ); } +# >>> + +# Compatibility functions <<< +zplugin() { zinit "$@"; } +zpcdreplay() { .zinit-compdef-replay -q; } +zpcdclear() { .zinit-compdef-clear -q; } +zpcompinit() { autoload -Uz compinit; compinit -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}"; } +zpcompdef() { ZINIT_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" ); } +# >>> + +# +# Source-executed code +# + +autoload add-zsh-hook +zmodload zsh/datetime && add-zsh-hook -- precmd @zinit-scheduler # zsh/datetime required for wait/load/unload ice-mods +functions -M -- zinit_scheduler_add 1 1 -zinit_scheduler_add_sh 2>/dev/null +zmodload zsh/zpty zsh/system 2>/dev/null + +# code <<< +builtin unsetopt noaliases +builtin alias zpl=zinit zplg=zinit zi=zinit zini=zinit + +.zinit-prepare-home + +# Simulate existence of _local/zinit plugin +# This will allow to cuninstall of its completion +ZINIT_REGISTERED_PLUGINS=( _local/zinit "${(u)ZINIT_REGISTERED_PLUGINS[@]:#_local/zinit}" ) +ZINIT_REGISTERED_STATES[_local/zinit]=1 + +# Add completions directory to fpath +fpath=( "${ZINIT[COMPLETIONS_DIR]}" "${fpath[@]}" ) + +# Inform Prezto that the compdef function is available +zstyle ':prezto:module:completion' loaded 1 + +# Colorize completions for commands unload, report, creinstall, cuninstall +zstyle ':completion:*:zinit:argument-rest:plugins' list-colors '=(#b)(*)/(*)==1;35=1;33' +zstyle ':completion:*:zinit:argument-rest:plugins' matcher 'r:|=** l:|=*' +zstyle ':completion:*:*:zinit:*' group-name "" +# >>> + +# module recompilation for the project rename <<< +if [[ -e ${${ZINIT[BIN_DIR]}}/zmodules/Src/zdharma/zplugin.so ]]; then + if [[ ! -f ${${ZINIT[BIN_DIR]}}/zmodules/COMPILED_AT || ( ${${ZINIT[BIN_DIR]}}/zmodules/COMPILED_AT -ot ${${ZINIT[BIN_DIR]}}/zmodules/RECOMPILE_REQUEST ) ]]; then + # Don't trust access times and verify hard stored values + [[ -e ${${ZINIT[BIN_DIR]}}/module/COMPILED_AT ]] && local compiled_at_ts="$(<${${ZINIT[BIN_DIR]}}/module/COMPILED_AT)" + [[ -e ${${ZINIT[BIN_DIR]}}/module/RECOMPILE_REQUEST ]] && local recompile_request_ts="$(<${${ZINIT[BIN_DIR]}}/module/RECOMPILE_REQUEST)" + + if [[ ${recompile_request_ts:-1} -gt ${compiled_at_ts:-0} ]]; then + builtin print -r -- "${ZINIT[col-error]}WARNING:${ZINIT[col-rst]}" \ + "${ZINIT[col-msg1]}Zplugin -> Zinit project rename needs a new" \ + "module - ${ZINIT[col-obj]}recompiling${ZINIT[col-rst]}…${reset_color}" + if command make -C "${ZINIT[BIN_DIR]}/zmodules" &>/dev/null; then + print -r -- "${ZINIT[col-pre]}Compilation successful!${ZINIT[col-rst]}" + else + print -r -- "${ZINIT[col-error]}Compilation failed.${ZINIT[col-rst]}" \ + "${ZINIT[col-pre]}You can enter the following command:${ZINIT[col-rst]}" \ + 'make -C "${ZINIT[BIN_DIR]}/zmodules' \ + "${ZINIT[col-pre]}to see the error messages and e.g.: report an issue" \ + "at GitHub${ZINIT[col-rst]}" + fi + + command date '+%s' >! "${ZINIT[BIN_DIR]}/zmodules/COMPILED_AT" + fi + fi +fi +# >>> + +# vim:ft=zsh:sw=4:sts=4:et:foldmarker=<<<,>>> diff --git a/zmodules/Src/zdharma/zplugin.c b/zmodules/Src/zdharma/zplugin.c index 9ca4be61..b125fa26 100644 --- a/zmodules/Src/zdharma/zplugin.c +++ b/zmodules/Src/zdharma/zplugin.c @@ -847,8 +847,8 @@ custom_try_source_file(char *file) /* If there is no zwc file, or if it is less recent than script file */ if ( ( !rn && ( rc || ( stc.st_mtime < stn.st_mtime ) ) ) && ( access( file_dup, W_OK ) == 0 || 0 == strcmp( - getsparam( "ZPLG_MOD_DEBUG" ) ? - getsparam( "ZPLG_MOD_DEBUG" ) : "0", + getsparam( "ZINIT_MOD_DEBUG" ) ? + getsparam( "ZINIT_MOD_DEBUG" ) : "0", "1" ) ) ) { char *args[] = { file, NULL }; @@ -866,8 +866,8 @@ custom_try_source_file(char *file) bin_zcompile("ZpluginModule_", args, &ops, 0); } else { if ( 0 == strcmp( - getsparam( "ZPLG_MOD_DEBUG" ) ? - getsparam( "ZPLG_MOD_DEBUG" ) : "0", + getsparam( "ZINIT_MOD_DEBUG" ) ? + getsparam( "ZINIT_MOD_DEBUG" ) : "0", "1" ) ) { zwarnnam( "ZpluginModule", @@ -1399,7 +1399,7 @@ void zpmod_usage() { "Command :\n" "\n" "Used by Zplugin internally to speed up loading plugins with tracking (reporting).\n" - "It extends the given field {plugin-ID} in $ZPLG_REPORTS hash, with the given string\n" + "It extends the given field {plugin-ID} in $ZINIT_REPORTS hash, with the given string\n" "{new-report-body}.\n" "\n" "Command :\n" @@ -1425,14 +1425,14 @@ zp_append_report( const char *nam, const char *target, int target_len, const cha char *target_string = NULL; int target_string_len = 0, new_extended_len = 0; - /* Get ZPLG_REPORTS associative array */ - pm = ( Param ) paramtab->getnode( paramtab, "ZPLG_REPORTS" ); + /* Get ZINIT_REPORTS associative array */ + pm = ( Param ) paramtab->getnode( paramtab, "ZINIT_REPORTS" ); if ( !pm ) { - zwarnnam( nam, "%d: Parameter $ZPLG_REPORTS isn't declared. Zplugin is not loaded? I.e. not sourced.", __LINE__ ); + zwarnnam( nam, "%d: Parameter $ZINIT_REPORTS isn't declared. Zplugin is not loaded? I.e. not sourced.", __LINE__ ); return 1; } - /* Get ZPLG_REPORTS[{target}] hashed Param */ + /* Get ZINIT_REPORTS[{target}] hashed Param */ ht = pm->u.hash; hn = gethashnode2( ht, target ); val_pm = ( Param ) hn; diff --git a/zplugin.zsh b/zplugin.zsh index 4ffe241f..5ee7f198 100644 --- a/zplugin.zsh +++ b/zplugin.zsh @@ -1,2401 +1,2 @@ -# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- -# Copyright (c) 2019 Sebastian Gniazdowski and contributors - -# -# Main state variables -# - -typeset -gaH ZPLG_REGISTERED_PLUGINS ZPLG_TASKS ZPLG_RUN -typeset -ga zsh_loaded_plugins -ZPLG_TASKS=( "" ) -# Snippets loaded, url -> file name -typeset -gAH ZPLGM ZPLG_REGISTERED_STATES ZPLG_SNIPPETS ZPLG_REPORTS ZPLG_ICES ZPLG_SICE ZPLG_CUR_BIND_MAP ZPLG_EXTS -typeset -gaH ZPLG_COMPDEF_REPLAY - -# -# Common needed values -# - -[[ ! -e ${ZPLGM[BIN_DIR]}/zplugin.zsh ]] && ZPLGM[BIN_DIR]= - -ZPLGM[ZERO]="$0" -[[ ! -o functionargzero || ${ZPLGM[ZERO]/\//} = ${ZPLGM[ZERO]} ]] && ZPLGM[ZERO]="${(%):-%N}" - -[[ -z ${ZPLGM[BIN_DIR]} ]] && ZPLGM[BIN_DIR]="${ZPLGM[ZERO]:h}" -[[ ${ZPLGM[BIN_DIR]} = \~* ]] && ZPLGM[BIN_DIR]=${~ZPLGM[BIN_DIR]} - -# Make ZPLGM[BIN_DIR] path absolute -if [[ ${ZPLGM[BIN_DIR]} != /* ]]; then - if [[ ${ZPLGM[BIN_DIR]} = . ]]; then - ZPLGM[BIN_DIR]="$PWD" - else - ZPLGM[BIN_DIR]="$PWD/${ZPLGM[BIN_DIR]}" - fi -fi - -# Final test of ZPLGM[BIN_DIR] -if [[ ! -e ${ZPLGM[BIN_DIR]}/zplugin.zsh ]]; then - print "Could not establish ZPLGM[BIN_DIR] hash field. It should point where Zplugin's git repository is." - return 1 -fi - -# User can override ZPLGM[HOME_DIR] -if [[ -z ${ZPLGM[HOME_DIR]} ]]; then - # Ignore ZDOTDIR if user manually put Zplugin to $HOME - if [[ -d $HOME/.zplugin ]]; then - ZPLGM[HOME_DIR]="$HOME/.zplugin" - else - ZPLGM[HOME_DIR]="${ZDOTDIR:-$HOME}/.zplugin" - fi -fi - -# Can be customized -: ${ZPLGM[PLUGINS_DIR]:=${ZPLGM[HOME_DIR]}/plugins} -: ${ZPLGM[COMPLETIONS_DIR]:=${ZPLGM[HOME_DIR]}/completions} -: ${ZPLGM[SNIPPETS_DIR]:=${ZPLGM[HOME_DIR]}/snippets} -: ${ZPLGM[SERVICES_DIR]:=${ZPLGM[HOME_DIR]}/services} -typeset -g ZPFX -: ${ZPFX:=${ZPLGM[HOME_DIR]}/polaris} - -ZPLGM[PLUGINS_DIR]=${~ZPLGM[PLUGINS_DIR]} ZPLGM[COMPLETIONS_DIR]=${~ZPLGM[COMPLETIONS_DIR]} -ZPLGM[SNIPPETS_DIR]=${~ZPLGM[SNIPPETS_DIR]} ZPLGM[SERVICES_DIR]=${~ZPLGM[SERVICES_DIR]} -export ZPFX=${~ZPFX} ZSH_CACHE_DIR="${ZSH_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache/zplugin}}" -[[ -n ${path[(re)$ZPFX/bin]} ]] || path=( "$ZPFX/bin" ${path[@]} ) - -[[ ! -d $ZSH_CACHE_DIR ]] && command mkdir -p "$ZSH_CACHE_DIR" -[[ -n ${ZPLGM[ZCOMPDUMP_PATH]} ]] && ZPLGM[ZCOMPDUMP_PATH]=${~ZPLGM[ZCOMPDUMP_PATH]} - -ZPLGM[UPAR]=";:^[[A;:^[OA;:\\e[A;:\\eOA;:${termcap[ku]/$'\e'/^\[};:${terminfo[kcuu1]/$'\e'/^\[};:" -ZPLGM[DOWNAR]=";:^[[B;:^[OB;:\\e[B;:\\eOB;:${termcap[kd]/$'\e'/^\[};:${terminfo[kcud1]/$'\e'/^\[};:" -ZPLGM[RIGHTAR]=";:^[[C;:^[OC;:\\e[C;:\\eOC;:${termcap[kr]/$'\e'/^\[};:${terminfo[kcuf1]/$'\e'/^\[};:" -ZPLGM[LEFTAR]=";:^[[D;:^[OD;:\\e[D;:\\eOD;:${termcap[kl]/$'\e'/^\[};:${terminfo[kcub1]/$'\e'/^\[};:" - -builtin autoload -Uz is-at-least -is-at-least 5.1 && ZPLGM[NEW_AUTOLOAD]=1 || ZPLGM[NEW_AUTOLOAD]=0 -#is-at-least 5.4 && ZPLGM[NEW_AUTOLOAD]=2 - -# Parameters - shadowing {{{ -ZPLGM[SHADOWING]=inactive ZPLGM[DTRACE]=0 -typeset -gH ZPLG_CUR_PLUGIN= -# }}} -# Parameters - ICE, {{{ -declare -gA ZPLG_1MAP ZPLG_2MAP -ZPLG_1MAP=( - OMZ:: https://github.com/ohmyzsh/ohmyzsh/trunk/ - PZT:: https://github.com/sorin-ionescu/prezto/trunk/ -) -ZPLG_2MAP=( - OMZ:: https://github.com/ohmyzsh/ohmyzsh/raw/master/ - PZT:: https://github.com/sorin-ionescu/prezto/raw/master/ -) -# }}} - -# Init {{{ -zmodload zsh/zutil || return 1 -zmodload zsh/parameter || return 1 -zmodload zsh/terminfo 2>/dev/null -zmodload zsh/termcap 2>/dev/null - -[[ ( ${+terminfo} = 1 && -n ${terminfo[colors]} ) || ( ${+termcap} = 1 && -n ${termcap[Co]} ) ]] && { - ZPLGM+=( - col-title "" - col-pname $'\e[33m' - col-uname $'\e[35m' - col-keyword $'\e[32m' - col-note $'\e[33m' - col-error $'\e[31m' - col-p $'\e[01m\e[34m' - col-bar $'\e[01m\e[35m' - col-info $'\e[32m' - col-info2 $'\e[32m' - col-uninst $'\e[01m\e[34m' - col-success $'\e[01m\e[32m' - col-failure $'\e[31m' - col-rst $'\e[0m' - col-bold $'\e[1m' - - col-pre $'\e[38;5;141m' - col-msg1 $'\e[0m' - col-msg2 $'\e[38;5;166m' - col-obj $'\e[38;5;221m' - col-obj2 $'\e[38;5;140m' - col-file $'\e[38;5;110m' - ) -} - -# List of hooks -typeset -gAH ZPLG_ZLE_HOOKS_LIST -ZPLG_ZLE_HOOKS_LIST=( - zle-line-init 1 - zle-line-finish 1 - paste-insert 1 - zle-isearch-exit 1 - zle-isearch-update 1 - zle-history-line-set 1 - zle-keymap-select 1 -) - -builtin setopt noaliases - -# }}} - -# -# Shadowing-related functions -# - -# FUNCTION: --zplg-reload-and-run {{{ -# Marks given function ($3) for autoloading, and executes it triggering the -# load. $1 is the fpath dedicated to the function, $2 are autoload options. -# This function replaces "autoload -X", because using that on older Zsh -# versions causes problems with traps. -# -# So basically one creates function stub that calls --zplg-reload-and-run() -# instead of "autoload -X". -# -# $1 - FPATH dedicated to function -# $2 - autoload options -# $3 - function name (one that needs autoloading) -# -# Author: Bart Schaefer ---zplg-reload-and-run () { - local fpath_prefix="$1" autoload_opts="$2" func="$3" - shift 3 - - # Unfunction caller function (its name is given) - unfunction -- "$func" - - local -a __fpath - __fpath=( ${fpath[@]} ) - local -a +h fpath - # See #127 - [[ $FPATH != *${${(@0)fpath_prefix}[1]}* ]] && \ - fpath=( ${(@0)fpath_prefix} ${__fpath[@]} ) - - # After this the function exists again - builtin autoload ${(s: :)autoload_opts} -- "$func" - - # User wanted to call the function, not only load it - "$func" "$@" -} # }}} -# FUNCTION: --zplg-shadow-autoload {{{ -# Function defined to hijack plugin's calls to `autoload' builtin. -# -# The hijacking is not only to gather report data, but also to -# run custom `autoload' function, that doesn't need FPATH. ---zplg-shadow-autoload () { - builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ - typesetsilent noshortloops unset - local -a opts - local func - - zparseopts -D -a opts ${(s::):-RTUXdkmrtWz} - - [[ $ZPLGM[CUR_USR] = % ]] && \ - local PLUGIN_DIR="$ZPLG_CUR_PLUGIN" || \ - local PLUGIN_DIR="${ZPLGM[PLUGINS_DIR]}/${${ZPLGM[CUR_USR]}:+${ZPLGM[CUR_USR]}---}${ZPLG_CUR_PLUGIN//\//---}" - - if (( ${+opts[(r)-X]} )); then - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Warning: Failed autoload ${(j: :)opts[@]} $*" - print -u2 "builtin autoload required for ${(j: :)opts[@]}" - return 1 - fi - if (( ${+opts[(r)-w]} )); then - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "-w-Autoload ${(j: :)opts[@]} ${(j: :)@}" - local +h FPATH="$PLUGINS_DIR:$FPATH" - builtin autoload ${opts[@]} "$@" - return 0 - fi - if [[ -n ${(M)@:#+X} ]]; then - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Autoload +X ${opts:+${(j: :)opts[@]} }${(j: :)${@:#+X}}" - local +h FPATH="$PLUGINS_DIR:$FPATH" - builtin autoload +X ${opts[@]} "${@:#+X}" - return 0 - fi - # Report ZPLUGIN's "native" autoloads - for func; do - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Autoload $func${opts:+ with options ${(j: :)opts[@]}}" - done - - local -a fpath_elements - fpath_elements=( ${fpath[(r)$PLUGIN_DIR/*]} ) - - for func; do - # Real autoload doesn't touch function if it already exists - # Author of the idea of FPATH-clean autoloading: Bart Schaefer - if (( ${+functions[$func]} != 1 )); then - builtin setopt noaliases - if [[ ${ZPLGM[NEW_AUTOLOAD]} = 2 ]]; then - builtin autoload ${opts[@]} "$PLUGIN_DIR/$func" - elif [[ ${ZPLGM[NEW_AUTOLOAD]} = 1 ]]; then - eval "function ${(q)func} { - local -a fpath - fpath=( ${(qqq)PLUGIN_DIR} ${(qqq@)fpath_elements} ${(qqq@)fpath} ) - builtin autoload -X ${(j: :)${(q-)opts[@]}} - }" - else - eval "function ${(q)func} { - --zplg-reload-and-run ${(qqq)PLUGIN_DIR}"$'\0'"${(pj,\0,)${(qqq)fpath_elements[@]}} ${(qq)opts[*]} ${(q)func} "'"$@" - }' - fi - builtin unsetopt noaliases - fi - done - - return 0 -} # }}} -# FUNCTION: --zplg-shadow-bindkey {{{ -# Function defined to hijack plugin's calls to `bindkey' builtin. -# -# The hijacking is to gather report data (which is used in unload). ---zplg-shadow-bindkey() { - builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ - typesetsilent noshortloops unset - is-at-least 5.3 && \ - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Bindkey ${(j: :)${(q+)@}}" || \ - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Bindkey ${(j: :)${(q)@}}" - - # Remember to perform the actual bindkey call - typeset -a pos - pos=( "$@" ) - - # Check if we have regular bindkey call, i.e. - # with no options or with -s, plus possible -M - # option - local -A opts - zparseopts -A opts -D ${(s::):-lLdDAmrsevaR} M: N: - - if (( ${#opts} == 0 || - ( ${#opts} == 1 && ${+opts[-M]} ) || - ( ${#opts} == 1 && ${+opts[-R]} ) || - ( ${#opts} == 1 && ${+opts[-s]} ) || - ( ${#opts} <= 2 && ${+opts[-M]} && ${+opts[-s]} ) || - ( ${#opts} <= 2 && ${+opts[-M]} && ${+opts[-R]} ) - )); then - local string="${(q)1}" widget="${(q)2}" - local quoted - - if [[ -n ${ZPLG_ICE[bindmap]} && ${ZPLG_CUR_BIND_MAP[empty]} -eq 1 ]]; then - local -a pairs - pairs=( "${(@s,;,)ZPLG_ICE[bindmap]}" ) - () { - builtin setopt localoptions extendedglob noksharrays noshwordsplit; - pairs=( "${(@)${(@)${(@s:->:)pairs}##[[:space:]]##}%%[[:space:]]##}" ) - } - ZPLG_CUR_BIND_MAP=( empty 0 ) - (( ${#pairs} > 1 && ${#pairs[@]} % 2 == 0 )) && ZPLG_CUR_BIND_MAP+=( "${pairs[@]}" ) - fi - - 1="${1#"${1%%[! $'\t']*}"}" # leading whitespace - 1="${1%"${1##*[! $'\t']}"}" # trailing whitespace - local bmap_val="${ZPLG_CUR_BIND_MAP[${1}]}" - if [[ -n $bmap_val ]]; then - string="${(q)bmap_val}" - pos[1]="$bmap_val" - -zplg-add-report "${ZPLGM[CUR_USPL2]}" ":::Bindkey: combination <$1> changed to <$bmap_val>${${(M)bmap_val:#hold}:+, i.e. ${ZPLGM[col-error]}unmapped${ZPLGM[col-rst]}}" - (( 1 )) - elif [[ ( -n ${bmap_val::=${ZPLG_CUR_BIND_MAP[UPAR]}} && -n ${${ZPLGM[UPAR]}[(r);:${(q)1};:]} ) || \ - ( -n ${bmap_val::=${ZPLG_CUR_BIND_MAP[DOWNAR]}} && -n ${${ZPLGM[DOWNAR]}[(r);:${(q)1};:]} ) || \ - ( -n ${bmap_val::=${ZPLG_CUR_BIND_MAP[RIGHTAR]}} && -n ${${ZPLGM[RIGHTAR]}[(r);:${(q)1};:]} ) || \ - ( -n ${bmap_val::=${ZPLG_CUR_BIND_MAP[LEFTAR]}} && -n ${${ZPLGM[LEFTAR]}[(r);:${(q)1};:]} ) - ]]; then - string="${(q)bmap_val}" - pos[1]="$bmap_val" - -zplg-add-report "${ZPLGM[CUR_USPL2]}" ":::Bindkey: combination <$1> recognized as cursor-key and changed to <${bmap_val}>${${(M)bmap_val:#hold}:+, i.e. ${ZPLGM[col-error]}unmapped${ZPLGM[col-rst]}}" - fi - [[ $bmap_val = hold ]] && return 0 - - local prev="${(q)${(s: :)$(builtin bindkey ${(Q)string})}[-1]#undefined-key}" - - # "-M map" given? - if (( ${+opts[-M]} )); then - local Mopt=-M - local Marg="${opts[-M]}" - - Mopt="${(q)Mopt}" - Marg="${(q)Marg}" - - quoted="$string $widget $prev $Mopt $Marg" - else - quoted="$string $widget $prev" - fi - - # -R given? - if (( ${+opts[-R]} )); then - local Ropt=-R - Ropt="${(q)Ropt}" - - if (( ${+opts[-M]} )); then - quoted="$quoted $Ropt" - else - # Two empty fields for non-existent -M arg - local space=_ - space="${(q)space}" - quoted="$quoted $space $space $Ropt" - fi - fi - - quoted="${(q)quoted}" - - # Remember the bindkey, only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[BINDKEYS__${ZPLGM[CUR_USPL2]}]+="$quoted " - # Remember for dtrace - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[BINDKEYS___dtrace/_dtrace]+="$quoted " - else - # bindkey -A newkeymap main? - # Negative indices for KSH_ARRAYS immunity - if [[ ${#opts} -eq 1 && ${+opts[-A]} = 1 && ${#pos} = 3 && ${pos[-1]} = main && ${pos[-2]} != -A ]]; then - # Save a copy of main keymap - (( ZPLGM[BINDKEY_MAIN_IDX] = ${ZPLGM[BINDKEY_MAIN_IDX]:-0} + 1 )) - local pname="${ZPLG_CUR_PLUGIN:-_dtrace}" - local name="${(q)pname}-main-${ZPLGM[BINDKEY_MAIN_IDX]}" - builtin bindkey -N "$name" main - - # Remember occurence of main keymap substitution, to revert on unload - local keys=_ widget=_ prev= optA=-A mapname="${name}" optR=_ - local quoted="${(q)keys} ${(q)widget} ${(q)prev} ${(q)optA} ${(q)mapname} ${(q)optR}" - quoted="${(q)quoted}" - - # Remember the bindkey, only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[BINDKEYS__${ZPLGM[CUR_USPL2]}]+="$quoted " - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[BINDKEYS___dtrace/_dtrace]+="$quoted " - - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Warning: keymap \`main' copied to \`${name}' because of \`${pos[-2]}' substitution" - # bindkey -N newkeymap [other] - elif [[ ${#opts} -eq 1 && ${+opts[-N]} = 1 ]]; then - local Nopt=-N - local Narg="${opts[-N]}" - - local keys=_ widget=_ prev= optN=-N mapname="${Narg}" optR=_ - local quoted="${(q)keys} ${(q)widget} ${(q)prev} ${(q)optN} ${(q)mapname} ${(q)optR}" - quoted="${(q)quoted}" - - # Remember the bindkey, only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[BINDKEYS__${ZPLGM[CUR_USPL2]}]+="$quoted " - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[BINDKEYS___dtrace/_dtrace]+="$quoted " - else - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Warning: last bindkey used non-typical options: ${(kv)opts[*]}" - fi - fi - - # Actual bindkey - builtin bindkey "${pos[@]}" - return $? # testable -} # }}} -# FUNCTION: --zplg-shadow-zstyle {{{ -# Function defined to hijack plugin's calls to `zstyle' builtin. -# -# The hijacking is to gather report data (which is used in unload). ---zplg-shadow-zstyle() { - builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ - typesetsilent noshortloops unset - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Zstyle $*" - - # Remember to perform the actual zstyle call - typeset -a pos - pos=( "$@" ) - - # Check if we have regular zstyle call, i.e. - # with no options or with -e - local -a opts - zparseopts -a opts -D ${(s::):-eLdgabsTtm} - - if [[ ${#opts} -eq 0 || ( ${#opts} -eq 1 && ${+opts[(r)-e]} = 1 ) ]]; then - # Have to quote $1, then $2, then concatenate them, then quote them again - local pattern="${(q)1}" style="${(q)2}" - local ps="$pattern $style" - ps="${(q)ps}" - - # Remember the zstyle, only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[ZSTYLES__${ZPLGM[CUR_USPL2]}]+="$ps " - # Remember for dtrace - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[ZSTYLES___dtrace/_dtrace]+=$ps - else - if [[ ! ${#opts[@]} = 1 && ( ${+opts[(r)-s]} = 1 || ${+opts[(r)-b]} = 1 || ${+opts[(r)-a]} = 1 || - ${+opts[(r)-t]} = 1 || ${+opts[(r)-T]} = 1 || ${+opts[(r)-m]} = 1 ) - ]]; then - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Warning: last zstyle used non-typical options: ${opts[*]}" - fi - fi - - # Actual zstyle - builtin zstyle "${pos[@]}" - return $? # testable -} # }}} -# FUNCTION: --zplg-shadow-alias {{{ -# Function defined to hijack plugin's calls to `alias' builtin. -# -# The hijacking is to gather report data (which is used in unload). ---zplg-shadow-alias() { - builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ - typesetsilent noshortloops unset - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Alias $*" - - # Remember to perform the actual alias call - typeset -a pos - pos=( "$@" ) - - local -a opts - zparseopts -a opts -D ${(s::):-gs} - - local a quoted tmp - for a in "$@"; do - local aname="${a%%[=]*}" - local avalue="${a#*=}" - - # Check if alias is to be redefined - (( ${+aliases[$aname]} )) && -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Warning: redefining alias \`${aname}', previous value: ${aliases[$aname]}" - - local bname=${(q)aliases[$aname]} - aname="${(q)aname}" - - if (( ${+opts[(r)-s]} )); then - tmp=-s - tmp="${(q)tmp}" - quoted="$aname $bname $tmp" - elif (( ${+opts[(r)-g]} )); then - tmp=-g - tmp="${(q)tmp}" - quoted="$aname $bname $tmp" - else - quoted="$aname $bname" - fi - - quoted="${(q)quoted}" - - # Remember the alias, only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[ALIASES__${ZPLGM[CUR_USPL2]}]+="$quoted " - # Remember for dtrace - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[ALIASES___dtrace/_dtrace]+="$quoted " - done - - # Actual alias - builtin alias "${pos[@]}" - return $? # testable -} # }}} -# FUNCTION: --zplg-shadow-zle {{{ -# Function defined to hijack plugin's calls to `zle' builtin. -# -# The hijacking is to gather report data (which is used in unload). ---zplg-shadow-zle() { - builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ - typesetsilent noshortloops unset - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Zle $*" - - # Remember to perform the actual zle call - typeset -a pos - pos=( "$@" ) - - set -- "${@:#--}" - - # Try to catch game-changing "-N" - if [[ ( $1 = -N && ( $# = 2 || $# = 3 ) ) || ( $1 = -C && $# = 4 ) ]]; then - # Hooks - if [[ ${ZPLG_ZLE_HOOKS_LIST[$2]} = 1 ]]; then - local quoted="$2" - quoted="${(q)quoted}" - # Remember only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[WIDGETS_DELETE__${ZPLGM[CUR_USPL2]}]+="$quoted " - # Remember for dtrace - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[WIDGETS_DELETE___dtrace/_dtrace]+="$quoted " - # These will be saved and restored - elif (( ${+widgets[$2]} )); then - # Have to remember original widget "$2" and - # the copy that it's going to be done - local widname="$2" targetfun="${${${(M)1:#-C}:+$4}:-$3}" - local completion_widget="${${(M)1:#-C}:+$3}" - local saved_widcontents="${widgets[$widname]}" - - widname="${(q)widname}" - completion_widget="${(q)completion_widget}" - targetfun="${(q)targetfun}" - saved_widcontents="${(q)saved_widcontents}" - local quoted="$1 $widname $completion_widget $targetfun $saved_widcontents" - quoted="${(q)quoted}" - # Remember only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[WIDGETS_SAVED__${ZPLGM[CUR_USPL2]}]+="$quoted " - # Remember for dtrace - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[WIDGETS_SAVED___dtrace/_dtrace]+="$quoted " - # These will be deleted - else - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Note: a new widget created via zle -N: \`$2'" - local quoted="$2" - quoted="${(q)quoted}" - # Remember only when load is in progress (it can be dstart that leads execution here) - [[ -n ${ZPLGM[CUR_USPL2]} ]] && ZPLGM[WIDGETS_DELETE__${ZPLGM[CUR_USPL2]}]+="$quoted " - # Remember for dtrace - [[ ${ZPLGM[DTRACE]} = 1 ]] && ZPLGM[WIDGETS_DELETE___dtrace/_dtrace]+="$quoted " - fi - fi - - # Actual zle - builtin zle "${pos[@]}" - return $? # testable -} # }}} -# FUNCTION: --zplg-shadow-compdef {{{ -# Function defined to hijack plugin's calls to `compdef' function. -# The hijacking is not only for reporting, but also to save compdef -# calls so that `compinit' can be called after loading plugins. ---zplg-shadow-compdef() { - builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ - typesetsilent noshortloops unset - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Saving \`compdef $*' for replay" - ZPLG_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" ) - - return 0 # testable -} # }}} -# FUNCTION: -zplg-shadow-on {{{ -# Turn on shadowing of builtins and functions according to passed -# mode ("load", "light", "light-b" or "compdef"). The shadowing is -# to gather report data, and to hijack `autoload', `bindkey' and -# `compdef' calls. --zplg-shadow-on() { - local mode="$1" - - # Enable shadowing only once - # - # One could expect possibility of widening of shadowing, however - # such sequence doesn't exist, e.g. "light" then "load"/"dtrace", - # "compdef" then "load"/"dtrace", "light" then "compdef", - # "compdef" then "light" - # - # It is always "dtrace" then "load" (i.e. dtrace then load) - # "dtrace" then "light" (i.e. dtrace then light load) - # "dtrace" then "compdef" (i.e. dtrace then snippet) - [[ ${ZPLGM[SHADOWING]} != inactive ]] && builtin return 0 - - ZPLGM[SHADOWING]="$mode" - - # The point about backuping is: does the key exist in functions array - # If it does exist, then it will also exist as ZPLGM[bkp-*] - - # Defensive code, shouldn't be needed - builtin unset "ZPLGM[bkp-autoload]" "ZPLGM[bkp-compdef]" # 0, E. - - if [[ $mode != compdef ]]; then - # 0. Used, but not in temporary restoration, which doesn't happen for autoload - (( ${+functions[autoload]} )) && ZPLGM[bkp-autoload]="${functions[autoload]}" - functions[autoload]='--zplg-shadow-autoload "$@";' - fi - - # E. Always shadow compdef - (( ${+functions[compdef]} )) && ZPLGM[bkp-compdef]="${functions[compdef]}" - functions[compdef]='--zplg-shadow-compdef "$@";' - - # Light and compdef shadowing stops here. Dtrace and load go on - [[ ( $mode = light && ${+ZPLG_ICE[trackbinds]} -eq 0 ) || $mode = compdef ]] && return 0 - - # Defensive code, shouldn't be needed. A, B, C, D - builtin unset "ZPLGM[bkp-bindkey]" "ZPLGM[bkp-zstyle]" "ZPLGM[bkp-alias]" "ZPLGM[bkp-zle]" - - # A. - (( ${+functions[bindkey]} )) && ZPLGM[bkp-bindkey]="${functions[bindkey]}" - functions[bindkey]='--zplg-shadow-bindkey "$@";' - - # B, when `zplugin light -b ...' or when `zplugin ice trackbinds ...; zplugin light ...' - [[ $mode = light-b || ( $mode = light && ${+ZPLG_ICE[trackbinds]} -eq 1 ) ]] && return 0 - - # B. - (( ${+functions[zstyle]} )) && ZPLGM[bkp-zstyle]="${functions[zstyle]}" - functions[zstyle]='--zplg-shadow-zstyle "$@";' - - # C. - (( ${+functions[alias]} )) && ZPLGM[bkp-alias]="${functions[alias]}" - functions[alias]='--zplg-shadow-alias "$@";' - - # D. - (( ${+functions[zle]} )) && ZPLGM[bkp-zle]="${functions[zle]}" - functions[zle]='--zplg-shadow-zle "$@";' - - builtin return 0 -} # }}} -# FUNCTION: -zplg-shadow-off {{{ -# Turn off shadowing completely for a given mode ("load", "light", -# "light-b" (i.e. the `trackbinds' mode) or "compdef"). --zplg-shadow-off() { - builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \ - typesetsilent noshortloops unset noaliases - local mode="$1" - - # Disable shadowing only once - # Disable shadowing only the way it was enabled first - [[ ${ZPLGM[SHADOWING]} = inactive || ${ZPLGM[SHADOWING]} != $mode ]] && return 0 - - ZPLGM[SHADOWING]=inactive - - if [[ $mode != compdef ]]; then - # 0. Unfunction autoload - (( ${+ZPLGM[bkp-autoload]} )) && functions[autoload]="${ZPLGM[bkp-autoload]}" || unfunction autoload - fi - - # E. Restore original compdef if it existed - (( ${+ZPLGM[bkp-compdef]} )) && functions[compdef]="${ZPLGM[bkp-compdef]}" || unfunction compdef - - # Light and compdef shadowing stops here - [[ ( $mode = light && ${+ZPLG_ICE[trackbinds]} -eq 0 ) || $mode = compdef ]] && return 0 - - # Unfunction shadowing functions - - # A. - (( ${+ZPLGM[bkp-bindkey]} )) && functions[bindkey]="${ZPLGM[bkp-bindkey]}" || unfunction bindkey - - # When `zplugin light -b ...' or when `zplugin ice trackbinds ...; zplugin light ...' - [[ $mode = light-b || ( $mode = light && ${+ZPLG_ICE[trackbinds]} -eq 1 ) ]] && return 0 - - # B. - (( ${+ZPLGM[bkp-zstyle]} )) && functions[zstyle]="${ZPLGM[bkp-zstyle]}" || unfunction zstyle - # C. - (( ${+ZPLGM[bkp-alias]} )) && functions[alias]="${ZPLGM[bkp-alias]}" || unfunction alias - # D. - (( ${+ZPLGM[bkp-zle]} )) && functions[zle]="${ZPLGM[bkp-zle]}" || unfunction zle - - return 0 -} # }}} -# FUNCTION: pmodload {{{ -# {function:pmodload} Compatibility with Prezto. Calls can be recursive. -(( ${+functions[pmodload]} )) || pmodload() { - while (( $# )); do - if zstyle -t ":prezto:module:$1" loaded 'yes' 'no'; then - shift - continue - else - [[ -z ${ZPLG_SNIPPETS[PZT::modules/$1${ZPLG_ICE[svn]-/init.zsh}]} && -z ${ZPLG_SNIPPETS[https://github.com/sorin-ionescu/prezto/trunk/modules/$1${ZPLG_ICE[svn]-/init.zsh}]} ]] && -zplg-load-snippet PZT::modules/"$1${ZPLG_ICE[svn]-/init.zsh}" - shift - fi - done -} -# }}} -# FUNCTION: -zplg-wrap-track-functions {{{ --zplg-wrap-track-functions() { - local user="$1" plugin="$2" id_as="$3" f - local -a wt - wt=( ${(@s.;.)ZPLG_ICE[wrap-track]} ) - for f in ${wt[@]}; do - functions[${f}-zplugin-bkp]="${functions[$f]}" - eval " -function $f { - ZPLGM[CUR_USR]=\"$user\" ZPLG_CUR_PLUGIN=\"$plugin\" ZPLGM[CUR_USPL2]=\"$id_as\" - -zplg-add-report \"\${ZPLGM[CUR_USPL2]}\" \"Note: === Starting to track function: $f ===\" - -zplg-diff \"\${ZPLGM[CUR_USPL2]}\" begin - -zplg-shadow-on load - functions[${f}]=\${functions[${f}-zplugin-bkp]} - ${f} \"\$@\" - -zplg-shadow-off load - -zplg-diff \"\${ZPLGM[CUR_USPL2]}\" end - -zplg-add-report \"\${ZPLGM[CUR_USPL2]}\" \"Note: === Ended tracking function: $f ===\" - ZPLGM[CUR_USR]= ZPLG_CUR_PLUGIN= ZPLGM[CUR_USPL2]= -}" - done -} -# }}} - -# -# Diff functions -# - -# FUNCTION: -zplg-diff-functions {{{ -# Implements detection of newly created functions. Performs -# data gathering, computation is done in *-compute(). -# -# $1 - user/plugin (i.e. uspl2 format) -# $2 - command, can be "begin" or "end" --zplg-diff-functions() { - local uspl2="$1" - local cmd="$2" - - [[ $cmd = begin ]] && \ - { [[ -z ${ZPLGM[FUNCTIONS_BEFORE__$uspl2]} ]] && \ - ZPLGM[FUNCTIONS_BEFORE__$uspl2]="${(j: :)${(qk)functions[@]}}" - } || \ - ZPLGM[FUNCTIONS_AFTER__$uspl2]+=" ${(j: :)${(qk)functions[@]}}" -} # }}} -# FUNCTION: -zplg-diff-options {{{ -# Implements detection of change in option state. Performs -# data gathering, computation is done in *-compute(). -# -# $1 - user/plugin (i.e. uspl2 format) -# $2 - command, can be "begin" or "end" --zplg-diff-options() { - local IFS=" " - - [[ $2 = begin ]] && \ - { [[ -z ${ZPLGM[OPTIONS_BEFORE__$uspl2]} ]] && \ - ZPLGM[OPTIONS_BEFORE__$1]="${(kv)options[@]}" - } || \ - ZPLGM[OPTIONS_AFTER__$1]+=" ${(kv)options[@]}" -} # }}} -# FUNCTION: -zplg-diff-env {{{ -# Implements detection of change in PATH and FPATH. -# -# $1 - user/plugin (i.e. uspl2 format) -# $2 - command, can be "begin" or "end" --zplg-diff-env() { - typeset -a tmp - local IFS=" " - - [[ $2 = begin ]] && { - { [[ -z ${ZPLGM[PATH_BEFORE__$uspl2]} ]] && \ - tmp=( "${(q)path[@]}" ) - ZPLGM[PATH_BEFORE__$1]="${tmp[*]}" - } - { [[ -z ${ZPLGM[FPATH_BEFORE__$uspl2]} ]] && \ - tmp=( "${(q)fpath[@]}" ) - ZPLGM[FPATH_BEFORE__$1]="${tmp[*]}" - } - } || { - tmp=( "${(q)path[@]}" ) - ZPLGM[PATH_AFTER__$1]+=" ${tmp[*]}" - tmp=( "${(q)fpath[@]}" ) - ZPLGM[FPATH_AFTER__$1]+=" ${tmp[*]}" - } -} # }}} -# FUNCTION: -zplg-diff-parameter {{{ -# Implements detection of change in any parameter's existence and type. -# Performs data gathering, computation is done in *-compute(). -# -# $1 - user/plugin (i.e. uspl2 format) -# $2 - command, can be "begin" or "end" --zplg-diff-parameter() { - typeset -a tmp - - [[ $2 = begin ]] && { - { [[ -z ${ZPLGM[PARAMETERS_BEFORE__$uspl2]} ]] && \ - ZPLGM[PARAMETERS_BEFORE__$1]="${(j: :)${(qkv)parameters[@]}}" - } - } || { - ZPLGM[PARAMETERS_AFTER__$1]+=" ${(j: :)${(qkv)parameters[@]}}" - } -} # }}} -# FUNCTION: -zplg-diff {{{ -# Performs diff actions of all types --zplg-diff() { - -zplg-diff-functions "$1" "$2" - -zplg-diff-options "$1" "$2" - -zplg-diff-env "$1" "$2" - -zplg-diff-parameter "$1" "$2" -} -# }}} - -# -# Utility functions -# - -# FUNCTION: -zplg-substitute {{{ --zplg-substitute() { - local -A __subst_map - __subst_map=( - "%ID%" "${id_as_clean:-$id_as}" - "%USER%" "$user" - "%PLUGIN%" "${plugin:-$save_url}" - "%URL%" "${save_url:-${user:+$user/}$plugin}" - "%DIR%" "${local_path:-$local_dir${dirname:+/$dirname}}" - '$ZPFX' "$ZPFX" - '${ZPFX}' "$ZPFX" - '%OS%' "${OSTYPE%(-gnu|[0-9]##)}" '%MACH%' "$MACHTYPE" '%CPU%' "$CPUTYPE" - '%VENDOR%' "$VENDOR" '%HOST%' "$HOST" '%UID%' "$UID" '%GID%' "$GID" - ) - if [[ -n ${ZPLG_ICE[param]} && ${ZPLGM[SUBST_DONE_FOR]} != ${ZPLG_ICE[param]} ]] { - ZPLGM[SUBST_DONE_FOR]="${ZPLG_ICE[param]}" - ZPLGM[PARAM_SUBST]= - local -a __params - __params=( ${(s.;.)ZPLG_ICE[param]} ) - local __param __from __to - for __param ( ${__params[@]} ) { - local __from="${${__param%%([[:space:]]|)(->|β†’)*}##[[:space:]]##}" \ - __to="${${__param##*(->|β†’)([[:space:]]|)}%[[:space:]]}" - ZPLGM[PARAM_SUBST]+="%${(q)__from}% ${(q)__to} " - } - } - - local -a __add - __add=( "${ZPLG_ICE[param]:+${(@Q)${(@z)ZPLGM[PARAM_SUBST]}}}" ) - (( ${#__add} % 2 == 0 )) && __subst_map+=( "${__add[@]}" ) - - local __var_name MATCH - integer MBEGIN MEND - () { - setopt localoptions extendedglob - for __var_name; do - local __value="${(P)__var_name}" - __value="${__value//(#m)(%[a-zA-Z0-9]##%|\$ZPFX|\$\{ZPFX\})/${__subst_map[$MATCH]}}" - : "${(P)__var_name::=$__value}" - done - } "$@" -} -# }}} -# FUNCTION: -zplg-any-to-user-plugin {{{ -# Allows elastic plugin-spec across the code. -# -# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) -# $2 - plugin (only when $1 - i.e. user - given) -# -# Returns user and plugin in $reply -# --zplg-any-to-user-plugin() { - # Two components given? - # That's a pretty fast track to call this function this way - if [[ -n $2 ]];then - 2=${~2} - reply=( "${1:-${${(M)2#/}:+%}}" "${${${(M)1#%}:+$2}:-${2//---//}}" ) - return 0 - fi - - # Is it absolute path? - if [[ $1 = /* ]]; then - reply=( "%" "$1" ) - return 0 - fi - - # Is it absolute path in zplugin format? - if [[ $1 = %* ]]; then - reply=( "%" "${${${1/\%HOME/$HOME}/\%SNIPPETS/${ZPLGM[SNIPPETS_DIR]}}#%}" ) - reply[2]=${~reply[2]} - return 0 - fi - - # Rest is for single component given - # It doesn't touch $2 - - if [[ $1 = */* ]]; then - reply=( "${1%%/*}" "${1#*/}" ) - return 0 - fi - - reply=( "${${(M)1#*---}%---}" "${${${1#*---}//---//}:-_unknown}" ) - - return 0 -} # }}} -# FUNCTION: -zplg-find-other-matches {{{ -# Plugin's main source file is in general `name.plugin.zsh'. However, -# there can be different conventions, if that file is not found, then -# this functions examines other conventions in order of most expected -# sanity. --zplg-find-other-matches() { - local pdir_path="$1" pbase="$2" - - if [[ -e $pdir_path/init.zsh ]]; then - reply=( "$pdir_path/init.zsh" ) - elif [[ -e $pdir_path/${pbase}.zsh-theme ]]; then - reply=( "$pdir_path/${pbase}.zsh-theme" ) - elif [[ -e $pdir_path/${pbase}.theme.zsh ]]; then - reply=( "$pdir_path/${pbase}.theme.zsh" ) - else - reply=( - $pdir_path/*.plugin.zsh(DN) $pdir_path/*.zsh-theme(DN) $pdir_path/init.zsh(DN) - $pdir_path/*.zsh(DN) $pdir_path/*.sh(DN) $pdir_path/.zshrc(DN) - ) - fi -} # }}} -# FUNCTION: -zplg-register-plugin {{{ -# Adds the plugin to ZPLG_REGISTERED_PLUGINS array and to the -# zsh_loaded_plugins array (managed according to the plugin standard: -# http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html) --zplg-register-plugin() { - local uspl2="$1" mode="$2" teleid="$3" - integer ret=0 - - if [[ -z ${ZPLG_REGISTERED_PLUGINS[(r)$uspl2]} ]]; then - ZPLG_REGISTERED_PLUGINS+=( "$uspl2" ) - else - # Allow overwrite-load, however warn about it - [[ -z ${ZPLGM[TEST]}${${+ZPLG_ICE[wait]}:#0}${ZPLG_ICE[load]}${ZPLG_ICE[subscribe]} && ${ZPLGM[MUTE_WARNINGS]} != 1 ]] && print "Warning: plugin \`$uspl2' already registered, will overwrite-load" - ret=1 - fi - - # Support Zsh plugin standard - zsh_loaded_plugins+=( "$teleid" ) - - # Full or light load? - [[ $mode = light ]] && ZPLG_REGISTERED_STATES[$uspl2]=1 || ZPLG_REGISTERED_STATES[$uspl2]=2 - - ZPLG_REPORTS[$uspl2]= ZPLG_CUR_BIND_MAP=( empty 1 ) - # Functions - ZPLGM[FUNCTIONS_BEFORE__$uspl2]= ZPLGM[FUNCTIONS_AFTER__$uspl2]= - ZPLGM[FUNCTIONS__$uspl2]= - # Objects - ZPLGM[ZSTYLES__$uspl2]= ZPLGM[BINDKEYS__$uspl2]= - ZPLGM[ALIASES__$uspl2]= - # Widgets - ZPLGM[WIDGETS_SAVED__$uspl2]= ZPLGM[WIDGETS_DELETE__$uspl2]= - # Rest (options and (f)path) - ZPLGM[OPTIONS__$uspl2]= ZPLGM[PATH__$uspl2]= - ZPLGM[OPTIONS_BEFORE__$uspl2]= ZPLGM[OPTIONS_AFTER__$uspl2]= - ZPLGM[FPATH__$uspl2]= - - return $ret -} # }}} -# FUNCTION: @zplg-register-z-annex {{{ -# Registers the z-annex inside Zplugin – i.e. an Zplugin extension -@zplg-register-annex() { - local name="$1" type="$2" handler="$3" helphandler="$4" icemods="$5" key="z-annex ${(q)2}" - ZPLG_EXTS[seqno]=$(( ${ZPLG_EXTS[seqno]:-0} + 1 )) - ZPLG_EXTS[$key${${(M)type#hook:}:+ ${ZPLG_EXTS[seqno]}}]="${ZPLG_EXTS[seqno]} z-annex-data: ${(q)name} ${(q)type} ${(q)handler} ${(q)helphandler} ${(q)icemods}" - ZPLG_EXTS[ice-mods]="${ZPLG_EXTS[ice-mods]}${icemods:+|}$icemods" -} -# }}} -# FUNCTION: @zsh-plugin-run-on-update {{{ -# The Plugin Standard required mechanism, see: -# http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html -@zsh-plugin-run-on-unload() { - ZPLG_ICE[ps-on-unload]="${(j.; .)@}" - -zplg-pack-ice "$id_as" "" -} -# }}} -# FUNCTION: @zsh-plugin-run-on-update {{{ -# The Plugin Standard required mechanism -@zsh-plugin-run-on-update() { - ZPLG_ICE[ps-on-update]="${(j.; .)@}" - -zplg-pack-ice "$id_as" "" -} -# }}} - -# -# Remaining functions -# - -# FUNCTION: -zplg-prepare-home {{{ -# Creates all directories needed by Zplugin, first checks if they -# already exist. --zplg-prepare-home() { - [[ -n ${ZPLGM[HOME_READY]} ]] && return - ZPLGM[HOME_READY]=1 - - [[ ! -d ${ZPLGM[HOME_DIR]} ]] && { - command mkdir -p "${ZPLGM[HOME_DIR]}" - # For compaudit - command chmod go-w "${ZPLGM[HOME_DIR]}" - # Also set up */bin and ZPFX in general - command mkdir 2>/dev/null -p ${ZPFX}/bin - } - [[ ! -d ${ZPLGM[PLUGINS_DIR]}/_local---zplugin ]] && { - command mkdir -p "${ZPLGM[PLUGINS_DIR]}/_local---zplugin" - # For compaudit - command chmod go-w "${ZPLGM[PLUGINS_DIR]}" - - # Prepare mock-like plugin for Zplugin itself - command ln -s "${ZPLGM[BIN_DIR]}/_zplugin" "${ZPLGM[PLUGINS_DIR]}/_local---zplugin" - - # Also set up */bin and ZPFX in general - command mkdir 2>/dev/null -p ${ZPFX}/bin - } - [[ ! -d ${ZPLGM[COMPLETIONS_DIR]} ]] && { - command mkdir "${ZPLGM[COMPLETIONS_DIR]}" - # For compaudit - command chmod go-w "${ZPLGM[COMPLETIONS_DIR]}" - - # Symlink _zplugin completion into _local---zplugin directory - command ln -s "${ZPLGM[PLUGINS_DIR]}/_local---zplugin/_zplugin" "${ZPLGM[COMPLETIONS_DIR]}" - - # Also set up */bin and ZPFX in general - command mkdir 2>/dev/null -p ${ZPFX}/bin - } - [[ ! -d ${ZPLGM[SNIPPETS_DIR]} ]] && { - command mkdir "${ZPLGM[SNIPPETS_DIR]}" - command chmod go-w "${ZPLGM[SNIPPETS_DIR]}" - ( cd ${ZPLGM[SNIPPETS_DIR]}; command ln -s OMZ::plugins plugins; ) - - # Also create the SERVICES_DIR - command mkdir -p "${ZPLGM[SERVICES_DIR]}" - command chmod go-w "${ZPLGM[SERVICES_DIR]}" - - # Also set up */bin and ZPFX in general - command mkdir 2>/dev/null -p ${ZPFX}/bin - } -} # }}} -# FUNCTION: -zplg-load-ices {{{ --zplg-load-ices() { - local id_as="$1" __key __path - local -a ice_order - ice_order=( - svn proto from teleid bindmap cloneopts id-as depth if wait load - unload blockf pick bpick src as ver silent lucid notify mv cp - atinit atclone atload atpull nocd run-atpull has cloneonly make - service trackbinds multisrc compile nocompile nocompletions - reset-prompt wrap-track reset sh \!sh bash \!bash ksh \!ksh csh - \!csh aliases countdown ps-on-unload ps-on-update trigger-load - light-mode is-snippet atdelete pack git verbose on-update-of - subscribe - ${(@us.|.)${ZPLG_EXTS[ice-mods]//\'\'/}} - ) - __path=${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}/._zplugin - [[ -d $__path ]] || __path=${ZPLGM[SNIPPETS_DIR]}/$id_as/._zplugin - for __key in "${ice_order[@]}"; do - (( ${+ZPLG_ICE[$__key]} )) && [[ ${ZPLG_ICE[$__key]} != +* ]] && continue - [[ -f $__path/$__key ]] && ZPLG_ICE[$__key]="$(<$__path/$__key)" - done - [[ -n ${ZPLG_ICE[on-update-of]} ]] && ZPLG_ICE[subscribe]="${ZPLG_ICE[subscribe]:-${ZPLG_ICE[on-update-of]}}" - [[ ${ZPLG_ICE[as]} = program ]] && ZPLG_ICE[as]=command - [[ -n ${ZPLG_ICE[pick]} ]] && ZPLG_ICE[pick]="${ZPLG_ICE[pick]//\$ZPFX/${ZPFX%/}}" - return 0 -} -# }}} -# FUNCTION: -zplg-load {{{ -# Implements the exposed-to-user action of loading a plugin. -# -# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin) -# $2 - plugin name, if the third format is used --zplg-load () { - typeset -F 3 SECONDS=0 - local mode="$3" rst=0 retval=0 key - -zplg-any-to-user-plugin "$1" "$2" - local user="${reply[-2]}" plugin="${reply[-1]}" id_as="${ZPLG_ICE[id-as]:-${reply[-2]}${${reply[-2]:#(%|/)*}:+/}${reply[-1]}}" - ZPLG_ICE[teleid]="${ZPLG_ICE[teleid]:-$user${${user:#(%|/)*}:+/}$plugin}" - - local -a arr - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:preinit <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" plugin "$user" "$plugin" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}}" preinit || \ - return $(( 10 - $? )) - done - - if [[ $user != % && ! -d ${ZPLGM[PLUGINS_DIR]}/${id_as//\//---} ]]; then - (( ${+functions[-zplg-setup-plugin-dir]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - reply=( "$user" "$plugin" ) REPLY=github - if (( ${+ZPLG_ICE[pack]} )) { - if ! -zplg-get-package "$user" "$plugin" "$id_as" \ - "${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}" \ - "${ZPLG_ICE[pack]:-default}" - then - zle && { print; zle .reset-prompt; } - return 1 - fi - id_as="${ZPLG_ICE[id-as]:-${user}${${user:#(%|/)*}:+/}$plugin}" - } - user="${reply[-2]}" plugin="${reply[-1]}" - ZPLG_ICE[teleid]="$user${${user:#(%|/)*}:+/}$plugin" - [[ $REPLY = snippet ]] && { - ZPLG_ICE[id-as]="${ZPLG_ICE[id-as]:-$id_as}" - -zplg-load-snippet $plugin - return $? - } - if ! -zplg-setup-plugin-dir "$user" "$plugin" "$id_as" "$REPLY"; then - zle && { print; zle .reset-prompt; } - return 1 - fi - zle && rst=1 - fi - - ZPLG_SICE[$id_as]= - -zplg-pack-ice "$id_as" - - (( ${+ZPLG_ICE[cloneonly]} )) && return 0 - - -zplg-register-plugin "$id_as" "$mode" "${ZPLG_ICE[teleid]}" - - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atinit <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" plugin "$user" "$plugin" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}}" \!atinit || \ - return $(( 10 - $? )) - done - - (( ${+ZPLG_ICE[atinit]} )) && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "${${${(M)user:#%}:+$plugin}:-${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}}"; } && eval "${ZPLG_ICE[atinit]}"; ((1)); } || eval "${ZPLG_ICE[atinit]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atinit <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" plugin "$user" "$plugin" "$id_as" "${${${(M)user:#%}:+$plugin}:-${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}}" atinit || \ - return $(( 10 - $? )) - done - - -zplg-load-plugin "$user" "$plugin" "$id_as" "$mode" "$rst"; retval=$? - (( ${+ZPLG_ICE[notify]} == 1 )) && { [[ $retval -eq 0 || -n ${(M)ZPLG_ICE[notify]#\!} ]] && { local msg; eval "msg=\"${ZPLG_ICE[notify]#\!}\""; -zplg-deploy-message @msg "$msg" } || -zplg-deploy-message @msg "notify: Plugin not loaded / loaded with problem, the return code: $retval"; } - (( ${+ZPLG_ICE[reset-prompt]} == 1 )) && -zplg-deploy-message @rst - ZPLGM[TIME_INDEX]=$(( ${ZPLGM[TIME_INDEX]:-0} + 1 )) - ZPLGM[TIME_${ZPLGM[TIME_INDEX]}_${id_as//\//---}]=$SECONDS - ZPLGM[AT_TIME_${ZPLGM[TIME_INDEX]}_${id_as//\//---}]=$EPOCHREALTIME - return $retval -} # }}} -# FUNCTION: -zplg-load-snippet {{{ -# Implements the exposed-to-user action of loading a snippet. -# -# $1 - url (can be local, absolute path) --zplg-load-snippet() { - typeset -F 3 SECONDS=0 - local -a opts tmp ice - zparseopts -E -D -a opts f -command u i || { print -r -- "Incorrect options (accepted ones: -f, --command)"; return 1; } - local url="$1" - integer correct=0 retval=0 - [[ -o ksharrays ]] && correct=1 - - [[ -n ${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && \ - local -a precm=( - emulate - ${${(M)${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!}:+-R} - ${${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!} - ${${ZPLG_ICE[(i)(\!|)bash]}:+-${(s: :):-o noshglob -o braceexpand -o kshglob}} - -c - ) - # Remove leading whitespace and trailing / - url="${${url#"${url%%[! $'\t']*}"}%/}" - ZPLG_ICE[teleid]="$url" - [[ ${ZPLG_ICE[as]} = null ]] && \ - ZPLG_ICE[pick]="${ZPLG_ICE[pick]:-/dev/null}" - - local local_dir dirname filename save_url="$url" id_as="${ZPLG_ICE[id-as]:-$url}" - [[ -z ${opts[(r)-u]} ]] && -zplg-pack-ice "$id_as" "" - - # Allow things like $OSTYPE in the URL - eval "url=\"$url\"" - - # - case A: called from `update --all', ZPLG_ICE not packed (above), static ice will win - # - case B: called from `snippet', ZPLG_ICE packed, so it will win - # - case C: called from `update', ZPLG_ICE packed, so it will win ← TODO - tmp=( "${(Q@)${(z@)ZPLG_SICE[$id_as]}}" ) - (( ${#tmp} > 1 && ${#tmp} % 2 == 0 )) && { ice=( "${(kv)ZPLG_ICE[@]}" "${tmp[@]}" ); ZPLG_ICE=( "${ice[@]}" ); } - tmp=( 1 ) - id_as="${ZPLG_ICE[id-as]:-$id_as}" - - # Oh-My-Zsh, Prezto and manual shorthands - (( ${+ZPLG_ICE[svn]} )) && { - [[ $url = *(OMZ::|robbyrussell*oh-my-zsh|ohmyzsh/ohmyzsh)* ]] && local ZSH="${ZPLGM[SNIPPETS_DIR]}" - url[1-correct,5-correct]="${ZPLG_1MAP[${url[1-correct,5-correct]}]:-${url[1-correct,5-correct]}}" - } || { - url[1-correct,5-correct]="${ZPLG_2MAP[${url[1-correct,5-correct]}]:-${url[1-correct,5-correct]}}" - } - - # Construct containing directory, extract final directory - # into handy-variable $dirname - filename="${${id_as%%\?*}:t}" - dirname="${${id_as%%\?*}:t}" - local_dir="${${${id_as%%\?*}:h}/:\/\//--}" - [[ $local_dir = . ]] && local_dir= || local_dir="${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--}" - local_dir="${ZPLGM[SNIPPETS_DIR]}${local_dir:+/$local_dir}" - - local -a arr - local key - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:preinit <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" preinit || \ - return $(( 10 - $? )) - done - - # Download or copy the file - if [[ -n ${opts[(r)(-f|-u)]} || ! -e $local_dir/$dirname/._zplugin ]]; then - (( ${+functions[-zplg-download-snippet]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - [[ $url = *github.com* && $url != */raw/* ]] && url="${${url/\/blob\///raw/}/\/tree\///raw/}" - -zplg-download-snippet "$save_url" "$url" "$id_as" "$local_dir" "$dirname" "$filename" "${opts[(r)-u]}" || tmp=( 0 ) - fi - - (( ${+ZPLG_ICE[cloneonly]} || !tmp[1-correct] )) && return 0 - - ZPLG_SNIPPETS[$id_as]="$id_as <${${ZPLG_ICE[svn]+svn}:-single file}>" - - [[ -z ${opts[(r)-u]} ]] && { ZPLGM[CUR_USPL2]="$id_as"; ZPLG_REPORTS[$id_as]=; } - - [[ -z ${opts[(r)-u]} ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atinit <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" \!atinit || \ - return $(( 10 - $? )) - done - } - - (( ${+ZPLG_ICE[atinit]} )) && [[ -z ${opts[(r)-u]} ]] && { local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && eval "${ZPLG_ICE[atinit]}"; ((1)); } || eval "${ZPLG_ICE[atinit]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - - [[ -z ${opts[(r)-u]} ]] && { - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atinit <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" atinit || \ - return $(( 10 - $? )) - done - } - - local -a list - local ZERO - - if [[ -z ${opts[(r)-u]} && -z ${opts[(r)--command]} && ( -z ${ZPLG_ICE[as]} || ${ZPLG_ICE[as]} = null ) ]]; then - # Source the file with compdef shadowing - if [[ ${ZPLGM[SHADOWING]} = inactive ]]; then - # Shadowing code is inlined from -zplg-shadow-on - (( ${+functions[compdef]} )) && ZPLGM[bkp-compdef]="${functions[compdef]}" || builtin unset "ZPLGM[bkp-compdef]" - functions[compdef]='--zplg-shadow-compdef "$@";' - ZPLGM[SHADOWING]=1 - else - (( ++ ZPLGM[SHADOWING] )) - fi - - # Add to fpath - [[ -d $local_dir/$dirname/functions ]] && { - [[ -z ${fpath[(r)$local_dir/$dirname/functions]} ]] && fpath+=( "$local_dir/$dirname/functions" ) - () { - builtin setopt localoptions extendedglob - autoload $local_dir/$dirname/functions/^([_.]*|prompt_*_setup|README*)(D-.N:t) - } - } - - # Source - if (( ${+ZPLG_ICE[svn]} == 0 )); then - [[ ${+ZPLG_ICE[pick]} = 0 ]] && list=( "$local_dir/$dirname/$filename" ) - [[ -n ${ZPLG_ICE[pick]} ]] && list=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZPLG_ICE[pick]}(DN) ) - else - if [[ -n ${ZPLG_ICE[pick]} ]]; then - list=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZPLG_ICE[pick]}(DN) ) - elif (( ${+ZPLG_ICE[pick]} == 0 )); then - list=( - $local_dir/$dirname/*.plugin.zsh(DN) $local_dir/$dirname/*.zsh-theme(DN) $local_dir/$dirname/init.zsh(DN) - $local_dir/$dirname/*.zsh(DN) $local_dir/$dirname/*.sh(DN) $local_dir/$dirname/.zshrc(DN) - ) - fi - fi - - [[ -f ${list[1-correct]} ]] && { - ZERO="${list[1-correct]}" - (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } - (( 0 == retval )) && [[ $id_as = PZT::* || $id_as = https://github.com/sorin-ionescu/prezto/* ]] && zstyle ":prezto:module:${${id_as%/init.zsh}:t}" loaded 'yes' - (( 1 )) - } || { [[ ${+ZPLG_ICE[pick]} = 1 && -z ${ZPLG_ICE[pick]} || ${ZPLG_ICE[pick]} = /dev/null ]] || { print -r -- "Snippet not loaded ($id_as)"; retval=1; } } - - [[ -n ${ZPLG_ICE[src]} ]] && { ZERO="${${(M)ZPLG_ICE[src]##/*}:-$local_dir/$dirname/${ZPLG_ICE[src]}}"; (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; } - [[ -n ${ZPLG_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; }; eval "reply=(${ZPLG_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$local_dir/$dirname/$fname}"; (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; done; } - - # Run the atload hooks right before atload ice - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atload <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" \!atload - done - - # Run the functions' wrapping & tracking requests - [[ -n ${ZPLG_ICE[wrap-track]} ]] && \ - -zplg-wrap-track-functions "$save_url" "" "$id_as" - - [[ ${ZPLG_ICE[atload][1]} = "!" ]] && { -zplg-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$local_dir/$dirname/-atload-"; local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && builtin eval "${ZPLG_ICE[atload]#\!}"; (( 1 )); } || eval "${ZPLG_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - - (( -- ZPLGM[SHADOWING] == 0 )) && { ZPLGM[SHADOWING]=inactive; builtin setopt noaliases; (( ${+ZPLGM[bkp-compdef]} )) && functions[compdef]="${ZPLGM[bkp-compdef]}" || unfunction compdef; builtin setopt aliases; } - elif [[ -n ${opts[(r)--command]} || ${ZPLG_ICE[as]} = command ]]; then - # Subversion - directory and multiple files possible - if (( ${+ZPLG_ICE[svn]} )); then - if [[ -n ${ZPLG_ICE[pick]} ]]; then - list=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZPLG_ICE[pick]}(DN) ) - [[ -n ${list[1-correct]} ]] && local xpath="${list[1-correct]:h}" xfilepath="${list[1-correct]}" - else - local xpath="$local_dir/$dirname" - fi - else - local xpath="$local_dir/$dirname" xfilepath="$local_dir/$dirname/$filename" - # This doesn't make sense, but users may come up with something - [[ -n ${ZPLG_ICE[pick]} ]] && { - list=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $local_dir/$dirname/${~ZPLG_ICE[pick]}(DN) ) - [[ -n ${list[1-correct]} ]] && xpath="${list[1-correct]:h}" xfilepath="${list[1-correct]}" - } - fi - [[ -z ${opts[(r)-u]} && -n $xpath && -z ${path[(er)$xpath]} ]] && path=( "${xpath%/}" ${path[@]} ) - [[ -n $xfilepath && -f $xfilepath && ! -x "$xfilepath" ]] && command chmod a+x "$xfilepath" ${list[@]:#$xfilepath} - [[ -z ${opts[(r)-u]} && ( -n ${ZPLG_ICE[src]} || -n ${ZPLG_ICE[multisrc]} || ${ZPLG_ICE[atload][1]} = "!" ) ]] && { - if [[ ${ZPLGM[SHADOWING]} = inactive ]]; then - # Shadowing code is inlined from -zplg-shadow-on - (( ${+functions[compdef]} )) && ZPLGM[bkp-compdef]="${functions[compdef]}" || builtin unset "ZPLGM[bkp-compdef]" - functions[compdef]='--zplg-shadow-compdef "$@";' - ZPLGM[SHADOWING]=1 - else - (( ++ ZPLGM[SHADOWING] )) - fi - } - - if [[ -z ${opts[(r)-u]} ]] { - if [[ -n ${ZPLG_ICE[src]} ]]; then - ZERO="${${(M)ZPLG_ICE[src]##/*}:-$local_dir/$dirname/${ZPLG_ICE[src]}}" - (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } - fi - [[ -n ${ZPLG_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; }; eval "reply=(${ZPLG_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$local_dir/$dirname/$fname}"; (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; done; } - - # Run the atload hooks right before atload ice - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atload <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" \!atload - done - - # Run the functions' wrapping & tracking requests - [[ -n ${ZPLG_ICE[wrap-track]} ]] && \ - -zplg-wrap-track-functions "$save_url" "" "$id_as" - - [[ ${ZPLG_ICE[atload][1]} = "!" ]] && { -zplg-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$local_dir/$dirname/-atload-"; local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && builtin eval "${ZPLG_ICE[atload]#\!}"; ((1)); } || eval "${ZPLG_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - } - - [[ -z ${opts[(r)-u]} && ( -n ${ZPLG_ICE[src]} || -n ${ZPLG_ICE[multisrc]} || ${ZPLG_ICE[atload][1]} = "!" ) ]] && { - (( -- ZPLGM[SHADOWING] == 0 )) && { ZPLGM[SHADOWING]=inactive; builtin setopt noaliases; (( ${+ZPLGM[bkp-compdef]} )) && functions[compdef]="${ZPLGM[bkp-compdef]}" || unfunction compdef; builtin setopt aliases; } - } - elif [[ ${ZPLG_ICE[as]} = completion ]]; then - ((1)) - fi - - # Updating – not sourcing, etc. - [[ -n ${opts[(r)-u]} ]] && return 0 - - (( ${+ZPLG_ICE[atload]} )) && [[ ${ZPLG_ICE[atload][1]} != "!" ]] && { ZERO="$local_dir/$dirname/-atload-"; local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; } && builtin eval "${ZPLG_ICE[atload]}"; ((1)); } || eval "${ZPLG_ICE[atload]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atload <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" atload - done - - (( ${+ZPLG_ICE[notify]} == 1 )) && { [[ $retval -eq 0 || -n ${(M)ZPLG_ICE[notify]#\!} ]] && { local msg; eval "msg=\"${ZPLG_ICE[notify]#\!}\""; -zplg-deploy-message @msg "$msg" } || -zplg-deploy-message @msg "notify: Plugin not loaded / loaded with problem, the return code: $retval"; } - (( ${+ZPLG_ICE[reset-prompt]} == 1 )) && -zplg-deploy-message @rst - - ZPLGM[CUR_USPL2]= - ZPLGM[TIME_INDEX]=$(( ${ZPLGM[TIME_INDEX]:-0} + 1 )) - ZPLGM[TIME_${ZPLGM[TIME_INDEX]}_${id_as}]=$SECONDS - ZPLGM[AT_TIME_${ZPLGM[TIME_INDEX]}_${id_as}]=$EPOCHREALTIME - return $retval -} # }}} -# FUNCTION: -zplg-compdef-replay {{{ -# Runs gathered compdef calls. This allows to run `compinit' -# after loading plugins. --zplg-compdef-replay() { - local quiet="$1" - typeset -a pos - - # Check if compinit was loaded - if [[ ${+functions[compdef]} = 0 ]]; then - print "Compinit isn't loaded, cannot do compdef replay" - return 1 - fi - - # In the same order - local cdf - for cdf in "${ZPLG_COMPDEF_REPLAY[@]}"; do - pos=( "${(z)cdf}" ) - # When ZPLG_COMPDEF_REPLAY empty (also when only white spaces) - [[ ${#pos[@]} = 1 && -z ${pos[-1]} ]] && continue - pos=( "${(Q)pos[@]}" ) - [[ $quiet = -q ]] || print "Running compdef ${pos[*]}" - compdef "${pos[@]}" - done - - return 0 -} # }}} -# FUNCTION: -zplg-compdef-clear {{{ -# Implements user-exposed functionality to clear gathered compdefs. --zplg-compdef-clear() { - local quiet="$1" count="${#ZPLG_COMPDEF_REPLAY}" - ZPLG_COMPDEF_REPLAY=( ) - [[ $quiet = -q ]] || print "Compdef-replay cleared (had $count entries)" -} # }}} -# FUNCTION: -zplg-add-report {{{ -# Adds a report line for given plugin. -# -# $1 - uspl2, i.e. user/plugin -# $2, ... - the text --zplg-add-report() { - # Use zplugin binary module if available - [[ -n $1 ]] && { (( ${+builtins[zpmod]} )) && zpmod report-append "$1" "$2"$'\n' || ZPLG_REPORTS[$1]+="$2"$'\n'; } - [[ ${ZPLGM[DTRACE]} = 1 ]] && { (( ${+builtins[zpmod]} )) && zpmod report-append _dtrace/_dtrace "$2"$'\n' || ZPLG_REPORTS[_dtrace/_dtrace]+="$2"$'\n'; } - return 0 -} # }}} -# FUNCTION: -zplg-load-plugin {{{ -# Lower-level function for loading a plugin. -# -# $1 - user -# $2 - plugin -# $3 - mode (light or load) --zplg-load-plugin() { - local user="$1" plugin="$2" id_as="$3" mode="$4" correct=0 retval=0 - ZPLGM[CUR_USR]="$user" ZPLG_CUR_PLUGIN="$plugin" ZPLGM[CUR_USPL2]="$id_as" - [[ -o ksharrays ]] && correct=1 - - [[ -n ${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] && \ - local -a precm=( - emulate - ${${(M)${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!}:+-R} - ${${ZPLG_ICE[(i)(\!|)(sh|bash|ksh|csh)]}#\!} - ${${ZPLG_ICE[(i)(\!|)bash]}:+-${(s: :):-o noshglob -o braceexpand -o kshglob}} - -c - ) - - [[ ${ZPLG_ICE[as]} = null ]] && \ - ZPLG_ICE[pick]="${ZPLG_ICE[pick]:-/dev/null}" - - local pbase="${${plugin:t}%(.plugin.zsh|.zsh|.git)}" - [[ $user = % ]] && local pdir_path="$plugin" || local pdir_path="${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}" - local pdir_orig="$pdir_path" key - - if [[ ${ZPLG_ICE[as]} = command ]]; then - reply=() - if [[ -n ${ZPLG_ICE[pick]} && ${ZPLG_ICE[pick]} != /dev/null ]]; then - reply=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $pdir_path/${~ZPLG_ICE[pick]}(DN) ) - [[ -n ${reply[1-correct]} ]] && pdir_path="${reply[1-correct]:h}" - fi - [[ -z ${path[(er)$pdir_path]} ]] && { - [[ $mode != light ]] && -zplg-diff-env "${ZPLGM[CUR_USPL2]}" begin - path=( "${pdir_path%/}" ${path[@]} ) - [[ $mode != light ]] && -zplg-diff-env "${ZPLGM[CUR_USPL2]}" end - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "$ZPLGM[col-info2]$pdir_path$ZPLGM[col-rst] added to \$PATH" - } - [[ -n ${reply[1-correct]} && ! -x "${reply[1-correct]}" ]] && command chmod a+x ${reply[@]} - - [[ -n ${ZPLG_ICE[src]} || -n ${ZPLG_ICE[multisrc]} || ${ZPLG_ICE[atload][1]} = "!" ]] && { - if [[ ${ZPLGM[SHADOWING]} = inactive ]]; then - (( ${+functions[compdef]} )) && ZPLGM[bkp-compdef]="${functions[compdef]}" || builtin unset "ZPLGM[bkp-compdef]" - functions[compdef]='--zplg-shadow-compdef "$@";' - ZPLGM[SHADOWING]=1 - else - (( ++ ZPLGM[SHADOWING] )) - fi - } - - local ZERO - [[ -n ${ZPLG_ICE[src]} ]] && { ZERO="${${(M)ZPLG_ICE[src]##/*}:-$pdir_orig/${ZPLG_ICE[src]}}"; (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; } - [[ -n ${ZPLG_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; }; eval "reply=(${ZPLG_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$pdir_orig/$fname}"; (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; done; } - - # Run the atload hooks right before atload ice - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atload <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" plugin "$user" "$plugin" "$id_as" "$pdir_orig" \!atload - done - - # Run the functions' wrapping & tracking requests - [[ -n ${ZPLG_ICE[wrap-track]} ]] && \ - -zplg-wrap-track-functions "$user" "$plugin" "$id_as" - - [[ ${ZPLG_ICE[atload][1]} = "!" ]] && { -zplg-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$pdir_orig/-atload-"; local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; } && builtin eval "${ZPLG_ICE[atload]#\!}"; } || eval "{ZPLG_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - - [[ -n ${ZPLG_ICE[src]} || -n ${ZPLG_ICE[multisrc]} || ${ZPLG_ICE[atload][1]} = "!" ]] && { - (( -- ZPLGM[SHADOWING] == 0 )) && { ZPLGM[SHADOWING]=inactive; builtin setopt noaliases; (( ${+ZPLGM[bkp-compdef]} )) && functions[compdef]="${ZPLGM[bkp-compdef]}" || unfunction compdef; builtin setopt aliases; } - } - elif [[ ${ZPLG_ICE[as]} = completion ]]; then - ((1)) - else - if [[ -n ${ZPLG_ICE[pick]} ]]; then - [[ ${ZPLG_ICE[pick]} = /dev/null ]] && reply=( /dev/null ) || reply=( ${(M)~ZPLG_ICE[pick]##/*}(DN) $pdir_path/${~ZPLG_ICE[pick]}(DN) ) - elif [[ -e $pdir_path/${pbase}.plugin.zsh ]]; then - reply=( "$pdir_path/${pbase}.plugin.zsh" ) - else - # The common file to source isn't there, so: - -zplg-find-other-matches "$pdir_path" "$pbase" - fi - - #[[ ${#reply} -eq 0 ]] && return 1 - - # Get first one - local fname="${reply[1-correct]:t}" - pdir_path="${reply[1-correct]:h}" - - -zplg-add-report "${ZPLGM[CUR_USPL2]}" "Source $fname ${${${(M)mode:#light}:+(no reporting)}:-$ZPLGM[col-info2](reporting enabled)$ZPLGM[col-rst]}" - - # Light and compdef mode doesn't do diffs and shadowing - [[ $mode != (light|light-b) ]] && -zplg-diff "${ZPLGM[CUR_USPL2]}" begin - - -zplg-shadow-on "${mode:-load}" - - # We need some state, but user wants his for his plugins - (( ${+ZPLG_ICE[blockf]} )) && { local -a fpath_bkp; fpath_bkp=( "${fpath[@]}" ); } - local ZERO="$pdir_path/$fname" - (( ${+ZPLG_ICE[aliases]} )) || builtin setopt noaliases - (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } - [[ -n ${ZPLG_ICE[src]} ]] && { ZERO="${${(M)ZPLG_ICE[src]##/*}:-$pdir_orig/${ZPLG_ICE[src]}}"; (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); }; } - [[ -n ${ZPLG_ICE[multisrc]} ]] && { local __oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; }; eval "reply=(${ZPLG_ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$pdir_orig/$fname}"; (( ${+ZPLG_ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; (( 1 )); } || builtin source "$ZERO" }; (( retval += $? )); } done; } - - # Run the atload hooks right before atload ice - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:\\\!atload <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" plugin "$user" "$plugin" "$id_as" "$pdir_orig" \!atload - done - - # Run the functions' wrapping & tracking requests - [[ -n ${ZPLG_ICE[wrap-track]} ]] && \ - -zplg-wrap-track-functions "$user" "$plugin" "$id_as" - - [[ ${ZPLG_ICE[atload][1]} = "!" ]] && { -zplg-add-report "$id_as" "Note: Starting to track the atload'!…' ice…"; ZERO="$pdir_orig/-atload-"; local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; } && builtin eval "${ZPLG_ICE[atload]#\!}"; ((1)); } || eval "${ZPLG_ICE[atload]#\!}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - (( ${+ZPLG_ICE[aliases]} )) || builtin unsetopt noaliases - (( ${+ZPLG_ICE[blockf]} )) && { fpath=( "${fpath_bkp[@]}" ); } - - -zplg-shadow-off "${mode:-load}" - - [[ $mode != (light|light-b) ]] && -zplg-diff "${ZPLGM[CUR_USPL2]}" end - fi - - [[ ${+ZPLG_ICE[atload]} = 1 && ${ZPLG_ICE[atload][1]} != "!" ]] && { ZERO="$pdir_orig/-atload-"; local __oldcd="$PWD"; (( ${+ZPLG_ICE[nocd]} == 0 )) && { () { setopt localoptions noautopushd; builtin cd -q "$pdir_orig"; } && builtin eval "${ZPLG_ICE[atload]}"; ((1)); } || eval "${ZPLG_ICE[atload]}"; () { setopt localoptions noautopushd; builtin cd -q "$__oldcd"; }; } - - reply=( "${(@on)ZPLG_EXTS[(I)z-annex hook:atload <->]}" ) - for key in "${reply[@]}"; do - arr=( "${(Q)${(z@)ZPLG_EXTS[$key]}[@]}" ) - "${arr[5]}" plugin "$user" "$plugin" "$id_as" "$pdir_orig" atload - done - - # Mark no load is in progress - ZPLGM[CUR_USR]= ZPLG_CUR_PLUGIN= ZPLGM[CUR_USPL2]= - - (( $5 )) && { print; zle .reset-prompt; } - return $retval -} # }}} -# FUNCTION: -zplg-add-fpath {{{ --zplg-add-fpath() { - [[ $1 = (-f|--front) ]] && { shift; integer front=1; } - -zplg-any-to-user-plugin "$1" "" - local id_as="$1" add_dir="$2" user="${reply[-2]}" plugin="${reply[-1]}" - (( front )) && \ - fpath[1,0]=${${${(M)user:#%}:+$plugin}:-${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}}${add_dir:+/$add_dir} || \ - fpath+=( - ${${${(M)user:#%}:+$plugin}:-${ZPLGM[PLUGINS_DIR]}/${id_as//\//---}}${add_dir:+/$add_dir} - ) -} -# }}} -# FUNCTION: -zplg-run {{{ -# Run code inside plugin's folder -# It uses the `correct' parameter from upper's scope zplugin() --zplg-run() { - if [[ $1 = (-l|--last) ]]; then - { set -- "${ZPLGM[last-run-plugin]:-$(<${ZPLGM[BIN_DIR]}/last-run-object.txt)}" "${@[2-correct,-1]}"; } &>/dev/null - [[ -z $1 ]] && { print "${ZPLGM[col-error]}Error: No last plugin available, please specify as the first argument${ZPLGM[col-rst]}"; return 1; } - else - integer __nolast=1 - fi - -zplg-any-to-user-plugin "$1" "" - local __id_as="$1" __user="${reply[-2]}" __plugin="${reply[-1]}" __oldpwd="$PWD" - () { - emulate -LR zsh - builtin cd &>/dev/null -q ${${${(M)__user:#%}:+$__plugin}:-${ZPLGM[PLUGINS_DIR]}/${__id_as//\//---}} || { - local local_dir=${${__id_as%%\?*}/:\/\//--} - local_dir=${${${${${local_dir#/}//\//--}//=/--EQ--}//\?/--QM--}//\&/--AMP--} - [[ -n $local_dir ]] && builtin cd &>/dev/null -q ${ZPLGM[SNIPPETS_DIR]}/$local_dir - } - } - if (( $? == 0 )); then - (( __nolast )) && { print -r "$1" >! ${ZPLGM[BIN_DIR]}/last-run-object.txt; } - ZPLGM[last-run-plugin]="$1" - eval "${@[2-correct,-1]}" - () { setopt localoptions noautopushd; builtin cd -q "$__oldpwd"; } - else - print "${ZPLGM[col-error]}Error: no such plugin or snippet${ZPLGM[col-rst]}" - fi -} -# }}} - -# -# Dtrace -# - -# FUNCTION: -zplg-debug-start {{{ -# Starts Dtrace, i.e. session tracking for changes in Zsh state. --zplg-debug-start() { - if [[ ${ZPLGM[DTRACE]} = 1 ]]; then - print "${ZPLGM[col-error]}Dtrace is already active, stop it first with \`dstop'${ZPLGM[col-rst]}" - return 1 - fi - - ZPLGM[DTRACE]=1 - - -zplg-diff _dtrace/_dtrace begin - - # Full shadowing on - -zplg-shadow-on dtrace -} # }}} -# FUNCTION: -zplg-debug-stop {{{ -# Stops Dtrace, i.e. session tracking for changes in Zsh state. --zplg-debug-stop() { - ZPLGM[DTRACE]=0 - - # Shadowing fully off - -zplg-shadow-off dtrace - - # Gather end data now, for diffing later - -zplg-diff _dtrace/_dtrace end -} # }}} -# FUNCTION: -zplg-clear-debug-report {{{ -# Forgets dtrace repport gathered up to this moment. --zplg-clear-debug-report() { - -zplg-clear-report-for _dtrace/_dtrace -} # }}} -# FUNCTION: -zplg-debug-unload {{{ -# Reverts changes detected by dtrace run. --zplg-debug-unload() { - if [[ ${ZPLGM[DTRACE]} = 1 ]]; then - print "Dtrace is still active, end it with \`dstop'" - else - -zplg-unload _dtrace _dtrace - fi -} # }}} - -# -# Ice support -# - -# FUNCTION: -zplg-ice {{{ -# Parses ICE specification (`zplg ice' subcommand), puts the result -# into ZPLG_ICE global hash. The ice-spec is valid for next command -# only (i.e. it "melts"), but it can then stick to plugin and activate -# e.g. at update. --zplg-ice() { - builtin setopt localoptions noksharrays extendedglob warncreateglobal typesetsilent noshortloops - integer retval - local bit exts="${~ZPLG_EXTS[ice-mods]//\'\'/}" - for bit; do - [[ $bit = (#b)(--|)(teleid|from|proto|cloneopts|depth|wait|load|\ -unload|on-update-of|subscribe|if|has|cloneonly|nocloneonly|blockf|\ -svn|nosvn|pick|nopick|src|bpick|as|ver|silent|lucid|mv|cp|atinit|\ -atload|atpull|atclone|run-atpull|norun-atpull|make|nomake|notify|\ -nonotify|reset-prompt|service|compile|nocompile|nocompletions|multisrc|\ -id-as|bindmap|trackbinds|notrackbinds|nocd|once|wrap-track|reset|\ -noreset|sh|\!sh|bash|\!bash|ksh|\!ksh|csh|\!csh|aliases|noaliases|\ -countdown|nocountdown|trigger-load|light-mode|is-snippet|pack|\ -atdelete|git|verbose|param${~exts})(*) - ]] && \ - ZPLG_ICES[${match[2]}]+="${ZPLG_ICES[${match[2]}]:+;}${match[3]#(:|=)}" || \ - break - retval+=1 - done - [[ ${ZPLG_ICES[as]} = program ]] && ZPLG_ICES[as]=command - [[ -n ${ZPLG_ICES[on-update-of]} ]] && ZPLG_ICES[subscribe]="${ZPLG_ICES[subscribe]:-${ZPLG_ICES[on-update-of]}}" - [[ -n ${ZPLG_ICES[pick]} ]] && ZPLG_ICES[pick]="${ZPLG_ICES[pick]//\$ZPFX/${ZPFX%/}}" - return $retval -} # }}} -# FUNCTION: -zplg-pack-ice {{{ -# Remembers all ice-mods, assigns them to concrete plugin. Ice spec -# is in general forgotten for second-next command (that's why it's -# called "ice" - it melts), however they glue to the object (plugin -# or snippet) mentioned in the next command – for later use with e.g. -# `zplugin update ...' --zplg-pack-ice() { - ZPLG_SICE[$1${1:+${2:+/}}$2]+="${(j: :)${(qkv)ZPLG_ICE[@]}} " - ZPLG_SICE[$1${1:+${2:+/}}$2]="${ZPLG_SICE[$1${1:+${2:+/}}$2]# }" - return 0 -} # }}} -# FUNCTION: -zplg-service {{{ -# Handles given service, i.e. obtains lock, runs it, or waits if no lock -# -# $1 - type "p" or "s" (plugin or snippet) -# $2 - mode - for plugin (light or load) -# $3 - id - URL or plugin ID or alias name (from id-as'') --zplg-service() { - local __tpe="$1" __mode="$2" __id="$3" __fle="${ZPLGM[SERVICES_DIR]}/${ZPLG_ICE[service]}.lock" __fd __cmd __tmp __lckd __strd=0 - { builtin print -n >! "$__fle"; } 2>/dev/null 1>&2 - [[ ! -e ${__fle:r}.fifo ]] && command mkfifo "${__fle:r}.fifo" 2>/dev/null 1>&2 - [[ ! -e ${__fle:r}.fifo2 ]] && command mkfifo "${__fle:r}.fifo2" 2>/dev/null 1>&2 - - typeset -g ZSRV_WORK_DIR="${ZPLGM[SERVICES_DIR]}" ZSRV_ID="${ZPLG_ICE[service]}" # should be also set by other p-m - - while (( 1 )); do - ( - while (( 1 )); do - [[ ! -f ${__fle:r}.stop ]] && if (( __lckd )) || zsystem 2>/dev/null 1>&2 flock -t 1 -f __fd -e $__fle; then - __lckd=1 - if (( ! __strd )) || [[ $__cmd = RESTART ]]; then - [[ $__tpe = p ]] && { __strd=1; -zplg-load "$__id" "" "$__mode"; } - [[ $__tpe = s ]] && { __strd=1; -zplg-load-snippet "$__id" ""; } - fi - __cmd= - while (( 1 )); do builtin read -t 32767 __cmd <>"${__fle:r}.fifo" && break; done - else - return 0 - fi - - [[ $__cmd = (#i)NEXT ]] && { kill -TERM "$ZSRV_PID"; builtin read -t 2 __tmp <>"${__fle:r}.fifo2"; kill -HUP "$ZSRV_PID"; exec {__fd}>&-; __lckd=0; __strd=0; builtin read -t 10 __tmp <>"${__fle:r}.fifo2"; } - [[ $__cmd = (#i)STOP ]] && { kill -TERM "$ZSRV_PID"; builtin read -t 2 __tmp <>"${__fle:r}.fifo2"; kill -HUP "$ZSRV_PID"; __strd=0; builtin print >! "${__fle:r}.stop"; } - [[ $__cmd = (#i)QUIT ]] && { kill -HUP ${sysparams[pid]}; return 1; } - [[ $__cmd != (#i)RESTART ]] && { __cmd=; builtin read -t 1 __tmp <>"${__fle:r}.fifo2"; } - done - ) || break - builtin read -t 1 __tmp <>"${__fle:r}.fifo2" - done >>! "$ZSRV_WORK_DIR/$ZSRV_ID".log 2>&1 -} -# }}} -# FUNCTION: -zplg-run-task {{{ -# A backend, worker function of -zplg-scheduler. It obtains the tasks -# index and a few of its properties (like the type: plugin, snippet, -# service plugin, service snippet) and executes it first checking for -# additional conditions (like non-numeric wait'' ice). -# -# $1 - the pass number, either 1st or 2nd pass -# $2 - the time assigned to the task -# $3 - type: plugin, snippet, service plugin, service snippet -# $4 - task's index in the ZPLGM[WAIT_ICE_...] fields -# $5 - mode: load or light -# $6 - the plugin-spec or snippet URL or alias name (from id-as'') --zplg-run-task() { - local __pass="$1" __t="$2" __tpe="$3" __idx="$4" __mode="$5" __id="${(Q)6}" __opt="${(Q)7}" __action __s=1 __retval=0 - - local -A ZPLG_ICE - ZPLG_ICE=( "${(@Q)${(z@)ZPLGM[WAIT_ICE_${__idx}]}}" ) - - local __id_as=${ZPLG_ICE[id-as]:-$__id} - - if [[ $__pass = 1 && ${${ZPLG_ICE[wait]#\!}%%[^0-9]([^0-9]|)([^0-9]|)([^0-9]|)} = <-> ]]; then - __action="${(M)ZPLG_ICE[wait]#\!}load" - elif [[ $__pass = 1 && -n ${ZPLG_ICE[wait]#\!} ]] && { eval "${ZPLG_ICE[wait]#\!}" || [[ $(( __s=0 )) = 1 ]]; }; then - __action="${(M)ZPLG_ICE[wait]#\!}load" - elif [[ -n ${ZPLG_ICE[load]#\!} && -n $(( __s=0 )) && $__pass = 3 && -z ${ZPLG_REGISTERED_PLUGINS[(r)$__id_as]} ]] && eval "${ZPLG_ICE[load]#\!}"; then - __action="${(M)ZPLG_ICE[load]#\!}load" - elif [[ -n ${ZPLG_ICE[unload]#\!} && -n $(( __s=0 )) && $__pass = 2 && -n ${ZPLG_REGISTERED_PLUGINS[(r)$__id_as]} ]] && eval "${ZPLG_ICE[unload]#\!}"; then - __action="${(M)ZPLG_ICE[unload]#\!}remove" - elif [[ -n ${ZPLG_ICE[subscribe]#\!} && -n $(( __s=0 )) && $__pass = 3 ]] && \ - { local -a fts_arr - eval "fts_arr=( ${ZPLG_ICE[subscribe]}(DNms-$(( EPOCHSECONDS - - ZPLGM[fts-${ZPLG_ICE[subscribe]}] ))) ); (( \${#fts_arr} ))" && \ - { ZPLGM[fts-${ZPLG_ICE[subscribe]}]="$EPOCHSECONDS"; __s=${+ZPLG_ICE[once]}; } || \ - (( 0 )) - } - then - __action="${(M)ZPLG_ICE[subscribe]#\!}load" - fi - - if [[ $__action = *load ]]; then - if [[ $__tpe = p ]]; then - -zplg-load "$__id" "" "$__mode"; (( __retval += $? )) - elif [[ $__tpe = s ]]; then - -zplg-load-snippet $__opt "${(@)=__id}"; (( __retval += $? )) - elif [[ $__tpe = p1 || $__tpe = s1 ]]; then - zpty -b "${__id//\//:} / ${ZPLG_ICE[service]}" '-zplg-service '"${(M)__tpe#?}"' "$__mode" "$__id"' - fi - (( ${+ZPLG_ICE[silent]} == 0 && ${+ZPLG_ICE[lucid]} == 0 && __retval == 0 )) && zle && zle -M "Loaded $__id" - elif [[ $__action = *remove ]]; then - (( ${+functions[-zplg-confirm]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-autoload.zsh - [[ $__tpe = p ]] && -zplg-unload "$__id_as" "" -q - (( ${+ZPLG_ICE[silent]} == 0 && ${+ZPLG_ICE[lucid]} == 0 && __retval == 0 )) && zle && zle -M "Unloaded $__id_as" - fi - - [[ ${REPLY::=$__action} = \!* ]] && zle && zle .reset-prompt - - return $__s -} -# }}} -# FUNCTION: -zplg-deploy-message {{{ -# Deploys a sub-prompt message to be displayed OR a `zle -# .reset-prompt' call to be invoked --zplg-deploy-message() { - [[ $1 = <-> && ( ${#} = 1 || ( $2 = (hup|nval|err) && ${#} = 2 ) ) ]] && { zle && { - local alltext text IFS=$'\n' nl=$'\n' - repeat 25; do read -r -u"$1" text; alltext+="${text:+$text$nl}"; done - [[ $alltext = @rst$nl ]] && { builtin zle reset-prompt; ((1)); } || \ - { [[ -n $alltext ]] && builtin zle -M "$alltext"; } - } - builtin zle -F "$1"; exec {1}<&- - return 0 - } - local THEFD=13371337 hasw - # The expansion is: if there is @sleep: pfx, then use what's after - # it, otherwise substitute 0 - exec {THEFD} < <(LANG=C sleep $(( 0.01 + ${${${(M)1#@sleep:}:+${1#@sleep:}}:-0} )); print -r -- ${1:#(@msg|@sleep:*)} "${@[2,-1]}"; ) - command true # workaround a Zsh bug, see: http://www.zsh.org/mla/workers/2018/msg00966.html - builtin zle -F "$THEFD" -zplg-deploy-message -} -# }}} - -# FUNCTION: -zplg-submit-turbo {{{ -# If `zplugin load`, `zplugin light` or `zplugin snippet` will be -# preceded with `wait', `load', `unload' or `on-update-of`/`subscribe' -# ice-mods then the plugin or snipped is to be loaded in turbo-mode, -# and this function adds it to internal data structures, so that -# -zplg-scheduler can run (load, unload) this as a task. --zplg-submit-turbo() { - local tpe="$1" mode="$2" opt_uspl2="$3" opt_plugin="$4" - - ZPLG_ICE[wait]="${ZPLG_ICE[wait]%%.[0-9]##}" - ZPLGM[WAIT_IDX]=$(( ${ZPLGM[WAIT_IDX]:-0} + 1 )) - ZPLGM[WAIT_ICE_${ZPLGM[WAIT_IDX]}]="${(j: :)${(qkv)ZPLG_ICE[@]}}" - ZPLGM[fts-${ZPLG_ICE[subscribe]}]="${ZPLG_ICE[subscribe]:+$EPOCHSECONDS}" - - [[ $tpe = s* ]] && \ - local id="${${opt_plugin:+$opt_plugin}:-$opt_uspl2}" || \ - local id="${${opt_plugin:+$opt_uspl2${${opt_uspl2:#%*}:+/}$opt_plugin}:-$opt_uspl2}" - - if [[ ${${ZPLG_ICE[wait]}%%[^0-9]([^0-9]|)([^0-9]|)([^0-9]|)} = (\!|.|)<-> ]]; then - ZPLG_TASKS+=( "$EPOCHSECONDS+${${ZPLG_ICE[wait]#(\!|.)}%%[^0-9]([^0-9]|)([^0-9]|)([^0-9]|)}+${${${(M)ZPLG_ICE[wait]%a}:+1}:-${${${(M)ZPLG_ICE[wait]%b}:+2}:-${${${(M)ZPLG_ICE[wait]%c}:+3}:-1}}} $tpe ${ZPLGM[WAIT_IDX]} ${mode:-_} ${(q)id} ${opt_plugin:+${(q)opt_uspl2}}" ) - elif [[ -n ${ZPLG_ICE[wait]}${ZPLG_ICE[load]}${ZPLG_ICE[unload]}${ZPLG_ICE[subscribe]} ]]; then - ZPLG_TASKS+=( "${${ZPLG_ICE[wait]:+0}:-1}+0+1 $tpe ${ZPLGM[WAIT_IDX]} ${mode:-_} ${(q)id} ${opt_plugin:+${(q)opt_uspl2}}" ) - fi -} -# }}} -# FUNCTION: -zplugin_scheduler_add_sh {{{ -# Copies task into ZPLG_RUN array, called when a task timeouts. -# A small function ran from pattern in /-substitution as a math -# function. --zplugin_scheduler_add_sh() { - local idx="$1" in_wait="$__ar2" in_abc="$__ar3" ver_wait="$__ar4" ver_abc="$__ar5" - if [[ ( $in_wait = $ver_wait || $in_wait -ge 4 ) && $in_abc = $ver_abc ]]; then - ZPLG_RUN+=( "${ZPLG_TASKS[$idx]}" ) - return 1 - else - return $idx - fi -} -# }}} -# FUNCTION: -zplg-scheduler {{{ -# Searches for timeout tasks, executes them. There's an array of tasks -# waiting for execution, this scheduler manages them, detects which ones -# should be run at current moment, decides to remove (or not) them from -# the array after execution. -# -# $1 - if "following", then it is non-first (second and more) -# invocation of the scheduler; this results in chain of `sched' -# invocations that results in repetitive -zplg-scheduler activity -# -# if "burst", then all tasks are marked timeout and executed one -# by one; this is handy if e.g. a docker image starts up and -# needs to install all turbo-mode plugins without any hesitation -# (delay), i.e. "burst" allows to run package installations from -# script, not from prompt -# --zplg-scheduler() { - integer __ret="${${ZPLGM[lro-data]%:*}##*:}" - # lro stands for lastarg-retval-option - [[ $1 = following ]] && sched +1 'ZPLGM[lro-data]="$_:$?:${options[printexitvalue]}"; -zplg-scheduler following "${ZPLGM[lro-data]%:*:*}"' - [[ -n $1 && $1 != (following*|burst) ]] && { local THEFD="$1"; zle -F "$THEFD"; exec {THEFD}<&-; } - [[ $1 = burst ]] && local -h EPOCHSECONDS=$(( EPOCHSECONDS+10000 )) - ZPLGM[START_TIME]="${ZPLGM[START_TIME]:-$EPOCHREALTIME}" - - integer __t=EPOCHSECONDS __i correct=0 - local -a match mbegin mend reply - local REPLY ANFD - - [[ -o ksharrays ]] && correct=1 - - [[ -n $1 ]] && { - () { - builtin emulate -L zsh - builtin setopt extendedglob - # Example entry: - # 1531252764+2+1 p 18 light zdharma/zsh-diff-so-fancy - # - # This either doesn't change ZPLG_TASKS entry - when - # __i is used in the ternary expression, or replaces - # an entry with "", i.e. ZPLG_TASKS[1] entry. - integer __idx1 __idx2 - local __ar2 __ar3 __ar4 __ar5 - for (( __idx1 = 0; __idx1 <= 4; __idx1 ++ )); do - for (( __idx2 = 1; __idx2 <= (__idx >= 4 ? 1 : 3); __idx2 ++ )); do - # The following substitution could be just (well, 'just'..) this: - # - # ZPLG_TASKS=( ${ZPLG_TASKS[@]/(#b)([0-9]##)+([0-9]##)+([1-3])(*)/ - # ${ZPLG_TASKS[$(( (${match[1]}+${match[2]}) <= $__t ? - # zplugin_scheduler_add(__i++, ${match[2]}, - # ${(M)match[3]%[1-3]}, __idx1, __idx2) : __i++ ))]}} ) - # - # However, there's a severe bug in Zsh <= 5.3.1 - use of the period - # (,) is impossible inside ${..//$arr[$(( ... ))]}. - __i=2 - - ZPLG_TASKS=( ${ZPLG_TASKS[@]/(#b)([0-9]##)+([0-9]##)+([1-3])(*)/${ZPLG_TASKS[ - $(( (__ar2=${match[2]}+1) ? ( - (__ar3=${(M)match[3]%[1-3]}) ? ( - (__ar4=__idx1+1) ? ( - (__ar5=__idx2) ? ( - (${match[1]}+${match[2]}) <= $__t ? - zplugin_scheduler_add(__i++) : __i++ ) - : 1 ) - : 1 ) - : 1 ) - : 1 ))]}} ) - ZPLG_TASKS=( "" ${ZPLG_TASKS[@]:#} ) - done - done - } - } || { - add-zsh-hook -d -- precmd -zplg-scheduler - add-zsh-hook -- chpwd -zplg-scheduler - () { - builtin emulate -L zsh - builtin setopt extendedglob - # No "+" in this pattern, it will match only "1531252764" - # in "1531252764+2" and replace it with current time - ZPLG_TASKS=( ${ZPLG_TASKS[@]/(#b)([0-9]##)(*)/$(( ${match[1]} <= 1 ? ${match[1]} : __t ))${match[2]}} ) - } - # There's a bug in Zsh: first sched call would not be issued - # until a key-press, if "sched +1 ..." would be called inside - # zle -F handler. So it's done here, in precmd-handle code. - sched +1 'ZPLGM[lro-data]="$_:$?:${options[printexitvalue]}"; -zplg-scheduler following ${ZPLGM[lro-data]%:*:*}' - - ANFD=13371337 # for older Zsh + noclobber option - exec {ANFD}< <(LANG=C command sleep 0.002; builtin print run;) - command true # workaround a Zsh bug, see: http://www.zsh.org/mla/workers/2018/msg00966.html - zle -F "$ANFD" -zplg-scheduler - } - - local __task __idx=0 __count=0 __idx2 - # All wait'' objects - for __task in "${ZPLG_RUN[@]}"; do - -zplg-run-task 1 "${(@z)__task}" && ZPLG_TASKS+=( "$__task" ) - [[ $(( ++__idx, __count += ${${REPLY:+1}:-0} )) -gt 0 && $1 != burst ]] && \ - { - ANFD=13371337 # for older Zsh + noclobber option - exec {ANFD}< <(LANG=C command sleep 0.0002; builtin print run;) - command true # workaround a Zsh bug, see: http://www.zsh.org/mla/workers/2018/msg00966.html - # The $? and $_ will be preserved automatically by Zsh - # – that's how calling the -F handler is implemented - zle -F "$ANFD" -zplg-scheduler - break - } - done - # All unload'' objects - for (( __idx2=1; __idx2 <= __idx; ++ __idx2 )); do - -zplg-run-task 2 "${(@z)ZPLG_RUN[__idx2-correct]}" - done - # All load'' & subscribe'' objects - for (( __idx2=1; __idx2 <= __idx; ++ __idx2 )); do - -zplg-run-task 3 "${(@z)ZPLG_RUN[__idx2-correct]}" - done - ZPLG_RUN[1-correct,__idx-correct]=() - - [[ ${ZPLGM[lro-data]##*:} = on ]] && return 0 || return $__ret -} -# }}} - -# -# Exposed functions -# - -# FUNCTION: zplugin {{{ -# Main function directly exposed to user, obtains subcommand and its -# arguments, has completion. -zplugin() { - local -A ZPLG_ICE - ZPLG_ICE=( "${(kv)ZPLG_ICES[@]}" ) - ZPLG_ICES=() - - integer retval=0 correct=0 - local -a match mbegin mend reply - local MATCH REPLY; integer MBEGIN MEND - - [[ -o ksharrays ]] && correct=1 - - local -A opt_map ICE_OPTS - opt_map=( - -q opt_-q,--quiet - --quiet opt_-q,--quiet - -r opt_-r,--reset - --reset opt_-r,--reset - --all opt_--all - --clean opt_--clean - --yes opt_-y,--yes - -y opt_-y,--yes - -f opt_-f,--force - --force opt_-f,--force - ) - - [[ $1 != (-h|--help|help|man|self-update|times|zstatus|load|light|unload|snippet|ls|ice|\ -update|status|report|delete|loaded|list|cd|create|edit|glance|stress|changes|recently|clist|\ -completions|cclear|cdisable|cenable|creinstall|cuninstall|csearch|compinit|dtrace|dstart|dstop|\ -dunload|dreport|dclear|compile|uncompile|compiled|cdlist|cdreplay|cdclear|srv|recall|\ -env-whitelist|bindkeys|module|add-fpath|fpath|run) || $1 = (load|light|snippet) ]] && \ - { - integer __is_snippet - if [[ $1 = (load|light|snippet) ]]; then - # Classic syntax -> simulate a call through the for-syntax - () { - setopt localoptions extendedglob - : ${@[@]//(#b)([ $'\t']##|(#s))(-b|--command|-f)([ $'\t']##|(#e))/${ICE_OPTS[${match[2]}]::=1}} - } "$@" - set -- "${@[@]:#(-b|--command|-f)}" - [[ $1 = light && -z ${ICE_OPTS[(I)-b]} ]] && ZPLG_ICE[light-mode]= - [[ $1 = snippet ]] && ZPLG_ICE[is-snippet]= || __is_snippet=-1 - shift - - ZPLG_ICES=( "${(kv)ZPLG_ICE[@]}" ) - ZPLG_ICE=() - 1="${1:+@}${1#@}${2:+/$2}" - (( $# > 1 )) && { shift -p $(( $# - 1 )); } - [[ -z $1 ]] && { - print "Argument needed, try: help" - return 1 - } - else - -zplg-ice "$@" - shift $? - if [[ $# -gt 0 && $1 != for ]]; then - print "Unknown command or ice: \`$1' (use \`help' to get usage information)" - return 1 - fi - [[ $1 = for ]] && shift - fi - integer __retval __had_wait - if (( $# )); then - local -a __ices - __ices=( "${(kv)ZPLG_ICES[@]}" ) - ZPLG_ICES=() - while (( $# )) { - -zplg-ice "$@" - shift $? - [[ -z ${ZPLG_ICES[subscribe]} ]] && unset 'ZPLG_ICES[subscribe]' - if [[ -n $1 ]]; then - ZPLG_ICE=( "${__ices[@]}" "${(kv)ZPLG_ICES[@]}" ) - ZPLG_ICES=() - - (( ${+ZPLG_ICE[pack]} )) && { - __had_wait=${+ZPLG_ICE[wait]} - -zplg-load-ices "${1#@}" - [[ -z ${ZPLG_ICE[wait]} && $__had_wait == 0 ]] && \ - unset 'ZPLG_ICE[wait]' - } - - [[ ${ZPLG_ICE[id-as]} = auto ]] && ZPLG_ICE[id-as]="${1:t}" - - [[ $__is_snippet -ge 0 ]] && { - [[ -n ${ZPLG_ICE[is-snippet]+1} || - ${1#@} = ((#i)(http(s|)|ftp(s|)):/|((OMZ|PZT)::))* - ]] && \ - __is_snippet=1 || \ - __is_snippet=0 - } - - if [[ -n ${ZPLG_ICE[trigger-load]} ]] { - () { - setopt localoptions extendedglob - local mode - (( __is_snippet > 0 )) && mode=snippet || mode="${${${ZPLG_ICE[light-mode]+light}}:-load}" - for MATCH ( ${(s.;.)ZPLG_ICE[trigger-load]} ) { - eval "${MATCH#!}() { - ${${(M)MATCH#!}:+unset -f ${MATCH#!}} - local a b; local -a ices - # The wait'' ice is filtered-out - for a b ( ${(qqkv@)${(kv@)ZPLG_ICE[(I)^(trigger-load|wait|light-mode)]}} ) { - ices+=( \"\$a\$b\" ) - } - zplugin ice \${ices[@]}; zplugin $mode ${(qqq)${1#@}} - ${${(M)MATCH#!}:+# Forward the call - eval ${MATCH#!} \$@} - }" - } - } "$@" - __retval+=$? - (( $# )) && shift - continue - } - - (( ${+ZPLG_ICE[if]} )) && { eval "${ZPLG_ICE[if]}" || { (( $# )) && shift; continue; }; } - (( ${+ZPLG_ICE[has]} )) && { (( ${+commands[${ZPLG_ICE[has]}]} )) || { (( $# )) && shift; continue; }; } - - ZPLG_ICE[wait]="${${(M)${+ZPLG_ICE[wait]}:#1}:+${(M)ZPLG_ICE[wait]#!}${${ZPLG_ICE[wait]#!}:-0}}" - if [[ -n ${ZPLG_ICE[wait]}${ZPLG_ICE[load]}${ZPLG_ICE[unload]}${ZPLG_ICE[service]}${ZPLG_ICE[subscribe]} ]]; then - ZPLG_ICE[wait]="${ZPLG_ICE[wait]:-${ZPLG_ICE[service]:+0}}" - if (( __is_snippet > 0 )); then - ZPLG_SICE[${${1#@}%%(/|//|///)}]= - -zplg-submit-turbo s${ZPLG_ICE[service]:+1} "" \ - "${${1#@}%%(/|//|///)}" \ - "${(k)ICE_OPTS[*]}" - else - ZPLG_SICE[${${${1#@}#https://github.com/}%%(/|//|///)}]= - -zplg-submit-turbo p${ZPLG_ICE[service]:+1} \ - "${${${ZPLG_ICE[light-mode]+light}}:-load}" \ - "${${${1#@}#https://github.com/}%%(/|//|///)}" "" - fi - __retval+=$? - else - if (( __is_snippet > 0 )); then - -zplg-load-snippet ${(k)ICE_OPTS[@]} "${${1#@}%%(/|//|///)}" - else - -zplg-load "${${${1#@}#https://github.com/}%%(/|//|///)}" "" \ - "${${ZPLG_ICE[light-mode]+light}:-${ICE_OPTS[(I)-b]:+light-b}}" - fi - __retval+=$? - fi - fi - (( $# )) && shift - } - fi - return __retval - } - - case "$1" in - (ice) - shift - -zplg-ice "$@" - ;; - (cdreplay) - -zplg-compdef-replay "$2"; retval=$? - ;; - (cdclear) - -zplg-compdef-clear "$2" - ;; - (add-fpath|fpath) - -zplg-add-fpath "${@[2-correct,-1]}" - ;; - (run) - -zplg-run "${@[2-correct,-1]}" - ;; - (dstart|dtrace) - -zplg-debug-start - ;; - (dstop) - -zplg-debug-stop - ;; - (man) - man "${ZPLGM[BIN_DIR]}/doc/zplugin.1" - ;; - (env-whitelist) - shift - [[ $1 = -v ]] && { shift; local verbose=1; } - [[ $1 = -h ]] && { shift; print "Usage: zplugin env-whitelist [-v] VAR1 ...\nSaves names (also patterns) of parameters left unchanged during an unload. -v - verbose."; } - (( $# == 0 )) && { - ZPLGM[ENV-WHITELIST]= - (( verbose )) && print "Cleared parameter whitelist" - } || { - ZPLGM[ENV-WHITELIST]+="${(j: :)${(q-kv)@}} " - (( verbose )) && print "Extended parameter whitelist" - } - ;; - (*) - # Check if there is a z-annex registered for the subcommand - reply=( ${ZPLG_EXTS[z-annex subcommand:${(q)1}]} ) - (( ${#reply} )) && { - reply=( "${(Q)${(z@)reply[1]}[@]}" ) - (( ${+functions[${reply[5]}]} )) && { "${reply[5]}" "$@"; return $?; } || - { print -r -- "(Couldn't find the subcommand-handler \`${reply[5]}' of the z-annex \`${reply[3]}')"; return 1; } - } - (( ${+functions[-zplg-confirm]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-autoload.zsh - case "$1" in - (zstatus) - -zplg-show-zstatus - ;; - (times) - -zplg-show-times "${@[2-correct,-1]}" - ;; - (self-update) - -zplg-self-update - ;; - (unload) - (( ${+functions[-zplg-unload]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-autoload.zsh - if [[ -z $2 && -z $3 ]]; then - print "Argument needed, try: help"; retval=1 - else - [[ $2 = -q ]] && { 5=-q; shift; } - # Unload given plugin. Cloned directory remains intact - # so as are completions - -zplg-unload "${2%%(/|//|///)}" "${${3:#-q}%%(/|//|///)}" "${${(M)4:#-q}:-${(M)3:#-q}}"; retval=$? - fi - ;; - (bindkeys) - -zplg-list-bindkeys - ;; - (update) - (( ${+ZPLG_ICE[if]} )) && { eval "${ZPLG_ICE[if]}" || return 1; } - (( ${+ZPLG_ICE[has]} )) && { (( ${+commands[${ZPLG_ICE[has]}]} )) || return 1; } - () { - setopt localoptions extendedglob - : ${@[@]//(#b)([ $'\t']##|(#s))(-q|--quiet|-r|--reset|-f|--force)([ $'\t']##|(#e))/${ICE_OPTS[${opt_map[${match[2]}]}]::=1}} - } "$@" - set -- "${@[@]:#(--quiet|-q|--reset|-r|-f|--force)}" - if [[ $2 = --all || ( -z $2 && -z $3 && -z ${ZPLG_ICE[teleid]} && -z ${ZPLG_ICE[id-as]} ) ]]; then - [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } - -zplg-update-or-status-all update; retval=$? - else - -zplg-update-or-status update "${${2%%(/|//|///)}:-${ZPLG_ICE[id-as]:-$ZPLG_ICE[teleid]}}" "${3%%(/|//|///)}"; retval=$? - fi - ;; - (status) - if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then - [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } - -zplg-update-or-status-all status; retval=$? - else - -zplg-update-or-status status "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? - fi - ;; - (report) - if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then - [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 3; } - -zplg-show-all-reports - else - -zplg-show-report "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? - fi - ;; - (loaded|list) - # Show list of loaded plugins - -zplg-show-registered-plugins "$2" - ;; - (clist|completions) - # Show installed, enabled or disabled, completions - # Detect stray and improper ones - -zplg-show-completions "$2" - ;; - (cclear) - # Delete stray and improper completions - -zplg-clear-completions - ;; - (cdisable) - if [[ -z $2 ]]; then - print "Argument needed, try: help"; retval=1 - else - local f="_${2#_}" - # Disable completion given by completion function name - # with or without leading _, e.g. cp, _cp - if -zplg-cdisable "$f"; then - (( ${+functions[-zplg-forget-completion]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - -zplg-forget-completion "$f" - print "Initializing completion system (compinit)..." - builtin autoload -Uz compinit - compinit -d ${ZPLGM[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZPLGM[COMPINIT_OPTS]}}" - else - retval=1 - fi - fi - ;; - (cenable) - if [[ -z $2 ]]; then - print "Argument needed, try: help"; retval=1 - else - local f="_${2#_}" - # Enable completion given by completion function name - # with or without leading _, e.g. cp, _cp - if -zplg-cenable "$f"; then - (( ${+functions[-zplg-forget-completion]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - -zplg-forget-completion "$f" - print "Initializing completion system (compinit)..." - builtin autoload -Uz compinit - compinit -d ${ZPLGM[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZPLGM[COMPINIT_OPTS]}}" - else - retval=1 - fi - fi - ;; - (creinstall) - (( ${+functions[-zplg-install-completions]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - # Installs completions for plugin. Enables them all. It's a - # reinstallation, thus every obstacle gets overwritten or removed - [[ $2 = -q ]] && { 5=-q; shift; } - -zplg-install-completions "${2%%(/|//|///)}" "${3%%(/|//|///)}" 1 "${(M)4:#-q}"; retval=$? - [[ -z ${(M)4:#-q} ]] && print "Initializing completion (compinit)..." - builtin autoload -Uz compinit - compinit -d ${ZPLGM[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZPLGM[COMPINIT_OPTS]}}" - ;; - (cuninstall) - if [[ -z $2 && -z $3 ]]; then - print "Argument needed, try: help"; retval=1 - else - (( ${+functions[-zplg-forget-completion]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - # Uninstalls completions for plugin - -zplg-uninstall-completions "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? - print "Initializing completion (compinit)..." - builtin autoload -Uz compinit - compinit -d ${ZPLGM[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZPLGM[COMPINIT_OPTS]}}" - fi - ;; - (csearch) - -zplg-search-completions - ;; - (compinit) - (( ${+functions[-zplg-forget-completion]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - -zplg-compinit; retval=$? - ;; - (dreport) - -zplg-show-debug-report - ;; - (dclear) - -zplg-clear-debug-report - ;; - (dunload) - -zplg-debug-unload - ;; - (compile) - (( ${+functions[-zplg-compile-plugin]} )) || builtin source ${ZPLGM[BIN_DIR]}/zplugin-install.zsh - if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then - [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } - -zplg-compile-uncompile-all 1; retval=$? - else - -zplg-compile-plugin "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? - fi - ;; - (uncompile) - if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then - [[ -z $2 ]] && { print -r -- "Assuming --all is passed"; sleep 2; } - -zplg-compile-uncompile-all 0; retval=$? - else - -zplg-uncompile-plugin "${2%%(/|//|///)}" "${3%%(/|//|///)}"; retval=$? - fi - ;; - (compiled) - -zplg-compiled - ;; - (cdlist) - -zplg-list-compdef-replay - ;; - (cd|delete|recall|edit|glance|changes|create|stress) - -zplg-"$1" "${@[2-correct,-1]%%(/|//|///)}"; retval=$? - ;; - (recently) - shift - -zplg-recently "$@"; retval=$? - ;; - (-h|--help|help|"") - -zplg-help - ;; - (ls) - shift - -zplg-ls "$@" - ;; - (srv) - () { setopt localoptions extendedglob warncreateglobal - [[ ! -e ${ZPLGM[SERVICES_DIR]}/"$2".fifo ]] && { print "No such service: $2"; } || - { [[ $3 = (#i)(next|stop|quit|restart) ]] && - { print "${(U)3}" >>! ${ZPLGM[SERVICES_DIR]}/"$2".fifo || print "Service $2 inactive"; retval=1; } || - { [[ $3 = (#i)start ]] && rm -f ${ZPLGM[SERVICES_DIR]}/"$2".stop || - { print "Unknown service-command: $3"; retval=1; } - } - } - } "$@" - ;; - (module) - -zplg-module "${@[2-correct,-1]}"; retval=$? - ;; - (*) - print "Unknown command \`$1' (use \`help' to get usage information)" - retval=1 - ;; - esac - ;; - esac - - return $retval -} # }}} -# FUNCTION: zpcdreplay {{{ -# A function that can be invoked from within `atinit', `atload', etc. -# ice-mod. It works like `zplugin cdreplay', which cannot be invoked -# from such hook ices. -zpcdreplay() { -zplg-compdef-replay -q; } -# }}} -# FUNCTION: zpcdclear {{{ -# A wrapper for `zplugin cdclear -q' which can be called from hook -# ices like the atinit'', atload'', etc. ices. -zpcdclear() { -zplg-compdef-clear -q; } -# }}} -# FUNCTION: zpcompinit {{{ -# A function that can be invoked from within `atinit', `atload', etc. -# ice-mod. It runs `autoload compinit; compinit' and respects -# ZPLGM[ZCOMPDUMP_PATH] and ZPLGM[COMPINIT_OPTS]. -zpcompinit() { autoload -Uz compinit; compinit -d ${ZPLGM[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZPLGM[COMPINIT_OPTS]}}"; } -# }}} -# FUNCTION: zpcompdef {{{ -# Stores compdef for a replay with `zpcdreplay' (turbo mode) or -# with `zplugin cdreplay' (normal mode). An utility functton of -# an undefined use case. -zpcompdef() { ZPLG_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" ); } -# }}} - -# -# Source-executed code -# - -autoload add-zsh-hook -zmodload zsh/datetime && add-zsh-hook -- precmd -zplg-scheduler # zsh/datetime required for wait/load/unload ice-mods -functions -M -- zplugin_scheduler_add 1 1 -zplugin_scheduler_add_sh 2>/dev/null -zmodload zsh/zpty zsh/system 2>/dev/null - -# code {{{ -builtin unsetopt noaliases -builtin alias zpl=zplugin zplg=zplugin - --zplg-prepare-home - -# Simulate existence of _local/zplugin plugin -# This will allow to cuninstall of its completion -ZPLG_REGISTERED_PLUGINS=( _local/zplugin "${(u)ZPLG_REGISTERED_PLUGINS[@]:#_local/zplugin}" ) -ZPLG_REGISTERED_STATES[_local/zplugin]=1 - -# Add completions directory to fpath -fpath=( "${ZPLGM[COMPLETIONS_DIR]}" "${fpath[@]}" ) - -# Inform Prezto that the compdef function is available -zstyle ':prezto:module:completion' loaded 1 - -# Colorize completions for commands unload, report, creinstall, cuninstall -zstyle ':completion:*:zplugin:argument-rest:plugins' list-colors '=(#b)(*)/(*)==1;35=1;33' -zstyle ':completion:*:zplugin:argument-rest:plugins' matcher 'r:|=** l:|=*' -zstyle ':completion:*:*:zplugin:*' group-name "" -# }}} - -# vim:ft=zsh:sw=4:sts=4:et +0="${(%):-%N}" +source ${0:A:h}/zinit.zsh