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

This commit is contained in:
Marc Cornellà 2022-08-01 20:54:45 +02:00
parent aa75eeea33
commit 4fcf52c2b1
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B
2 changed files with 42 additions and 32 deletions

View file

@ -1,11 +1,14 @@
# 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}"
eval '
function acs(){ function acs(){
(( $+commands[python3] )) || { (( $+commands[python3] )) || {
echo "[error] No python executable detected" echo "[error] No python executable detected"
return return
} }
alias | python3 ${functions_source[$0]:h}/cheatsheet.py $@ alias | python3 "'"${0:h}"'/cheatsheet.py" "$@"
} }
'

View file

@ -1,6 +1,12 @@
#!/usr/bin/bash #!/usr/bin/bash
# shellcheck disable=SC1090,SC2154 # shellcheck disable=SC1090,SC2154
# 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 '
proxy() { proxy() {
# deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead # deprecate $DEFAULT_PROXY, use SHELLPROXY_URL instead
if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then if [[ -n "$DEFAULT_PROXY" && -z "$SHELLPROXY_URL" ]]; then
@ -17,7 +23,7 @@ proxy() {
fi fi
# the proxy.py script is in the same directory as this function # the proxy.py script is in the same directory as this function
local proxy="${functions_source[$0]:A:h}/proxy.py" local proxy="'"${0:h}"'/proxy.py"
# capture the output of the proxy script and bail out if it fails # capture the output of the proxy script and bail out if it fails
local output local output
@ -27,6 +33,7 @@ proxy() {
# evaluate the output generated by the proxy script # evaluate the output generated by the proxy script
source <(echo "$output") source <(echo "$output")
} }
'
_proxy() { _proxy() {
local -r commands=('enable' 'disable' 'status') local -r commands=('enable' 'disable' 'status')