fix: don't use `$functions_source` for compatibility with zsh < 5.4

parent aa75eeea
# with lots of 3rd-party amazing aliases installed, just need something to explore it quickly. # Handle $0 according to the standard:
# # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
# - acs: alias cheatsheet 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
# group alias by command, pass addition argv to grep. 0="${${(M)0:#/*}:-$PWD/$0}"
function acs(){
(( $+commands[python3] )) || { eval '
echo "[error] No python executable detected" function acs(){
return (( $+commands[python3] )) || {
echo "[error] No python executable detected"
return
}
alias | python3 "'"${0:h}"'/cheatsheet.py" "$@"
} }
alias | python3 ${functions_source[$0]:h}/cheatsheet.py $@ '
}
#!/usr/bin/bash #!/usr/bin/bash
# shellcheck disable=SC1090,SC2154 # shellcheck disable=SC1090,SC2154
proxy() { # Handle $0 according to the standard:
# deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
echo >&2 "proxy: DEFAULT_PROXY is deprecated, use SHELLPROXY_URL instead" 0="${${(M)0:#/*}:-$PWD/$0}"
SHELLPROXY_URL="$DEFAULT_PROXY"
unset DEFAULT_PROXY eval '
fi proxy() {
# deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead
# deprecate CONFIG_PROXY, use SHELLPROXY_CONFIG instead if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then
if [[ -n "$CONFIG_PROXY" && -z "$SHELLPROXY_CONFIG" ]]; then echo >&2 "proxy: DEFAULT_PROXY is deprecated, use SHELLPROXY_URL instead"
echo >&2 "proxy: CONFIG_PROXY is deprecated, use SHELLPROXY_CONFIG instead" SHELLPROXY_URL="$DEFAULT_PROXY"
SHELLPROXY_CONFIG="$CONFIG_PROXY" unset DEFAULT_PROXY
unset CONFIG_PROXY fi
fi
# deprecate CONFIG_PROXY, use SHELLPROXY_CONFIG instead
# the proxy.py script is in the same directory as this function if [[ -n "$CONFIG_PROXY" && -z "$SHELLPROXY_CONFIG" ]]; then
local proxy="${functions_source[$0]:A:h}/proxy.py" echo >&2 "proxy: CONFIG_PROXY is deprecated, use SHELLPROXY_CONFIG instead"
SHELLPROXY_CONFIG="$CONFIG_PROXY"
# capture the output of the proxy script and bail out if it fails unset CONFIG_PROXY
local output fi
output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" ||
return $? # the proxy.py script is in the same directory as this function
local proxy="'"${0:h}"'/proxy.py"
# evaluate the output generated by the proxy script
source <(echo "$output") # capture the output of the proxy script and bail out if it fails
} local output
output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" ||
return $?
# evaluate the output generated by the proxy script
source <(echo "$output")
}
'
_proxy() { _proxy() {
local -r commands=('enable' 'disable' 'status') local -r commands=('enable' 'disable' 'status')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment