2021-07-29 00:37:35 -07:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
# YES_ZSH
|
2021-07-29 05:44:12 -07:00
|
|
|
# NO_BASH
|
|
|
|
# NO_DASH
|
2021-09-23 06:48:05 -07:00
|
|
|
# NO_ASH
|
2021-07-29 00:37:35 -07:00
|
|
|
|
|
|
|
# wat - a better and recursive which/whence
|
|
|
|
# via: https://leahneukirchen.org/dotfiles/tools.html
|
2021-07-30 19:41:16 -07:00
|
|
|
wat() { ### @-
|
2021-08-01 09:27:25 -07:00
|
|
|
### wat — a better and recursive which/whence. for zsh only.
|
|
|
|
###
|
|
|
|
### written by [leah2.](https://leahneukirchen.org/)
|
2021-07-29 00:37:35 -07:00
|
|
|
( # constrain unalias
|
|
|
|
for cmd; do
|
|
|
|
if (( $+aliases[$cmd] )); then
|
|
|
|
printf '%s: aliased to %s\n' $cmd $aliases[$cmd]
|
|
|
|
local -a words=(${${(z)aliases[$cmd]}:#(*=*|rlwrap|noglob|command)})
|
|
|
|
unalias $cmd
|
|
|
|
if [[ $words[1] == '\'* ]]; then
|
|
|
|
words[1]=${words[1]#'\'}
|
|
|
|
unalias $words[1] 2>/dev/null
|
|
|
|
fi
|
|
|
|
wat $words[1]
|
|
|
|
elif (( $+functions[$cmd] )); then
|
|
|
|
whence -v $cmd
|
|
|
|
whence -f $cmd
|
|
|
|
elif (( $+commands[$cmd] )); then
|
|
|
|
wat $commands[$cmd]
|
|
|
|
elif [[ -h $cmd ]]; then
|
|
|
|
file $cmd
|
|
|
|
wat $cmd:A
|
|
|
|
elif [[ -x $cmd ]]; then
|
|
|
|
file $cmd
|
|
|
|
else
|
|
|
|
which $cmd
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:48:46 -07:00
|
|
|
[ -n "${preload+-}" ] || wat "$@"
|