Skip to content

Commit

Permalink
fix: Don't escape exclamation marks in hook keys
Browse files Browse the repository at this point in the history
Exclamation marks (per default) get escaped in interactive mode,
but not in non-interactive modes. In this case it meant that zinit
would not find any hooks which implements the ices when running in
non-interactive mode (e.g. in a script). This in turn would NOT result
in errors but would just silently not execute any of the ices which
of course would be a bad thing(tm).

#199 has the details...

Closes: #199
  • Loading branch information
jankatins committed May 3, 2022
1 parent 596d2e7 commit bdd74a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
4 changes: 3 additions & 1 deletion doc/zsdoc/zinit.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,9 @@ ____
Registers the z-annex inside Zinit – i.e. an Zinit extension
____
Has 4 line(s). Doesn't call other functions.
Has 6 line(s). Doesn't call other functions.
Uses feature(s): _setopt_
Called by:
Expand Down
18 changes: 9 additions & 9 deletions zinit-autoload.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1566,9 +1566,9 @@ ZINIT[EXTENDED_GLOB]=""
# Run annexes' atpull hooks (the before atpull-ice ones).
# The gh-r / GitHub releases block.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down Expand Up @@ -1655,9 +1655,9 @@ ZINIT[EXTENDED_GLOB]=""
# Run annexes' atpull hooks (the before atpull-ice ones).
# The regular Git-plugins block.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down Expand Up @@ -1702,9 +1702,9 @@ ZINIT[EXTENDED_GLOB]=""
# Run annexes' atpull hooks (the before atpull[^!]…-ice ones).
# Block common for Git and gh-r plugins.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\\\!atpull-pre <->]}
${${ICE[atpull]:#\!*}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\\\!atpull-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\!atpull-pre <->]}
${${ICE[atpull]:#\!*}:+${(on)ZINIT_EXTS[(I)z-annex hook:\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down
36 changes: 18 additions & 18 deletions zinit-install.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
# Store ices at clone of a plugin
.zinit-store-ices "$local_path/._zinit" ICE "" "" "" ""
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\!atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:\!atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\!atclone-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down Expand Up @@ -996,9 +996,9 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
# Run annexes' atpull hooks (the before atpull-ice ones).
# The SVN block.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down Expand Up @@ -1090,9 +1090,9 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
# The URL-snippet block.
if [[ $update = -u && $ZINIT[annex-multi-flag:pull-active] -ge 1 ]] {
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-pre <->]}
${${ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down Expand Up @@ -1150,9 +1150,9 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
# The local-file snippets block.
if [[ $update = -u ]] {
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down Expand Up @@ -1226,9 +1226,9 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
# Run annexes' atpull hooks (the before atpull-ice ones).
# The block is common to all 3 snippet types.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\\\!atpull-pre <->]}
${${ICE[atpull]:#\!*}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\\\!atpull-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\!atpull-pre <->]}
${${ICE[atpull]:#\!*}:+${(on)ZINIT_EXTS[(I)z-annex hook:\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand All @@ -1243,9 +1243,9 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
# Run annexes' atclone hooks (the before atclone-ice ones)
# The block is common to all 3 snippet types.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-post <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\!atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:\!atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\!atclone-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
Expand Down
16 changes: 10 additions & 6 deletions zinit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,10 @@ builtin setopt noaliases
# FUNCTION: @zinit-register-hook. [[[
# Registers the z-annex inside Zinit – i.e. an Zinit extension
@zinit-register-hook() {
emulate -LR zsh
# nobanghist to disable adding backslash escaping to "!", which is used in a lot of hocks and behaves differently
# in interactive sessions (escapes !) and non-interactive ones (does not)
builtin setopt extendedglob warncreateglobal typesetsilent noshortloops nobanghist
local name="$1" type="$2" handler="$3" icemods="$4" key="zinit ${(q)2}"
ZINIT_EXTS2[seqno]=$(( ${ZINIT_EXTS2[seqno]:-0} + 1 ))
ZINIT_EXTS2[$key${${(M)type#hook:}:+ ${ZINIT_EXTS2[seqno]}}]="${ZINIT_EXTS2[seqno]} z-annex-data: ${(q)name} ${(q)type} ${(q)handler} '' ${(q)icemods}"
Expand Down Expand Up @@ -1381,7 +1385,7 @@ builtin setopt noaliases

ZINIT[CUR_USPL2]="$id_as" ZINIT_REPORTS[$id_as]=

reply=( ${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atinit-<-> <->]} )
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 || \
Expand Down Expand Up @@ -1443,7 +1447,7 @@ builtin setopt noaliases
[[ -n ${ICE[multisrc]} ]] && { local ___oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; }; eval "reply=(${ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$___oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$local_dir/$dirname/$fname}"; (( ${+ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); builtin source "$ZERO"; }; }; (( retval += $? )); }; done; }

# Run the atload hooks right before atload ice.
reply=( ${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atload-<-> <->]} )
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
Expand Down Expand Up @@ -1497,7 +1501,7 @@ builtin setopt noaliases
[[ -n ${ICE[multisrc]} ]] && { local ___oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$local_dir/$dirname"; }; eval "reply=(${ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$___oldcd"; }; local fname; for fname in "${reply[@]}"; do ZERO="${${(M)fname:#/*}:-$local_dir/$dirname/$fname}"; (( ${+ICE[silent]} )) && { { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( retval += $? )); ((1)); } || { ((1)); { [[ -n $precm ]] && { builtin ${precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); builtin source "$ZERO"; }; }; (( retval += $? )); }; done; }

# Run the atload hooks right before atload ice.
reply=( ${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atload-<-> <->]} )
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
Expand Down Expand Up @@ -1614,7 +1618,7 @@ builtin setopt noaliases
.zinit-setup-params && local ${(Q)reply[@]}
}

reply=( ${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atinit-<-> <->]} )
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 || \
Expand Down Expand Up @@ -1715,7 +1719,7 @@ builtin setopt noaliases
[[ -n ${ICE[multisrc]} ]] && { local ___oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$___pdir_orig"; }; eval "reply=(${ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$___oldcd"; }; local ___fname; for ___fname in "${reply[@]}"; do ZERO="${${(M)___fname:#/*}:-$___pdir_orig/$___fname}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { ((1)); { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); }; done; }

# Run the atload hooks right before atload ice.
reply=( ${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atload-<-> <->]} )
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
Expand Down Expand Up @@ -1766,7 +1770,7 @@ builtin setopt noaliases
[[ -n ${ICE[multisrc]} ]] && { local ___oldcd="$PWD"; () { setopt localoptions noautopushd; builtin cd -q "$___pdir_orig"; }; eval "reply=(${ICE[multisrc]})"; () { setopt localoptions noautopushd; builtin cd -q "$___oldcd"; }; for ___fname in "${reply[@]}"; do ZERO="${${(M)___fname:#/*}:-$___pdir_orig/$___fname}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); } done; }

# Run the atload hooks right before atload ice.
reply=( ${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atload-<-> <->]} )
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
Expand Down

0 comments on commit bdd74a6

Please sign in to comment.