From 4fcf52c2b1e086596d96b04f9c1ff3d742194857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 1 Aug 2022 20:54:45 +0200 Subject: [PATCH] fix: don't use `$functions_source` for compatibility with zsh < 5.4 --- plugins/aliases/aliases.plugin.zsh | 23 +++++----- plugins/shell-proxy/shell-proxy.plugin.zsh | 51 ++++++++++++---------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/plugins/aliases/aliases.plugin.zsh b/plugins/aliases/aliases.plugin.zsh index 4e1e0558e..9864de957 100644 --- a/plugins/aliases/aliases.plugin.zsh +++ b/plugins/aliases/aliases.plugin.zsh @@ -1,11 +1,14 @@ -# with lots of 3rd-party amazing aliases installed, just need something to explore it quickly. -# -# - acs: alias cheatsheet -# group alias by command, pass addition argv to grep. -function acs(){ - (( $+commands[python3] )) || { - echo "[error] No python executable detected" - return +# Handle $0 according to the standard: +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" + +eval ' + function acs(){ + (( $+commands[python3] )) || { + echo "[error] No python executable detected" + return + } + alias | python3 "'"${0:h}"'/cheatsheet.py" "$@" } - alias | python3 ${functions_source[$0]:h}/cheatsheet.py $@ -} +' diff --git a/plugins/shell-proxy/shell-proxy.plugin.zsh b/plugins/shell-proxy/shell-proxy.plugin.zsh index 9d45b5269..4fdbe9322 100644 --- a/plugins/shell-proxy/shell-proxy.plugin.zsh +++ b/plugins/shell-proxy/shell-proxy.plugin.zsh @@ -1,32 +1,39 @@ #!/usr/bin/bash # shellcheck disable=SC1090,SC2154 -proxy() { - # deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead - if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then - echo >&2 "proxy: DEFAULT_PROXY is deprecated, use SHELLPROXY_URL instead" - SHELLPROXY_URL="$DEFAULT_PROXY" - unset DEFAULT_PROXY - fi +# Handle $0 according to the standard: +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" - # deprecate CONFIG_PROXY, use SHELLPROXY_CONFIG instead - if [[ -n "$CONFIG_PROXY" && -z "$SHELLPROXY_CONFIG" ]]; then - echo >&2 "proxy: CONFIG_PROXY is deprecated, use SHELLPROXY_CONFIG instead" - SHELLPROXY_CONFIG="$CONFIG_PROXY" - unset CONFIG_PROXY - fi +eval ' + proxy() { + # deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead + if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then + echo >&2 "proxy: DEFAULT_PROXY is deprecated, use SHELLPROXY_URL instead" + SHELLPROXY_URL="$DEFAULT_PROXY" + unset DEFAULT_PROXY + fi - # the proxy.py script is in the same directory as this function - local proxy="${functions_source[$0]:A:h}/proxy.py" + # deprecate CONFIG_PROXY, use SHELLPROXY_CONFIG instead + if [[ -n "$CONFIG_PROXY" && -z "$SHELLPROXY_CONFIG" ]]; then + echo >&2 "proxy: CONFIG_PROXY is deprecated, use SHELLPROXY_CONFIG instead" + SHELLPROXY_CONFIG="$CONFIG_PROXY" + unset CONFIG_PROXY + fi - # 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 $? + # 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() { local -r commands=('enable' 'disable' 'status')