typeset - Strange array lookup in zsh -
looking @ this example pyenv-virtualenv
:
typeset -g -a precmd_functions if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; precmd_functions=(_pyenv_virtualenv_hook \$precmd_functions); fi
_pyenv_virtualenv_hook
function declared earlier in file.
i believe code checking see whether _pyenv_virtualenv_hook
injected precmd_functions
, don't understand syntax.
what purpose of (r)
in array lookup?
the zsh guide chapter on substitutions explains (r)
flag:
the
(r)
flag takes pattern , substitutes first element of array matched.
so snippet describe: if element in array (i.e. lookup returns non-zero value). obfuscated further because code quote assigned string evaluated, therefore dollar signs escaped (\$
).
Comments
Post a Comment