mirror of
https://github.com/notwa/rc
synced 2024-11-05 04:39:03 -08:00
36 lines
965 B
Text
36 lines
965 B
Text
|
#!/usr/bin/env zsh
|
||
|
# YES_ZSH
|
||
|
|
||
|
# wat - a better and recursive which/whence
|
||
|
# via: https://leahneukirchen.org/dotfiles/tools.html
|
||
|
wat() {
|
||
|
( # 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
|
||
|
)
|
||
|
}
|
||
|
|
||
|
[ "${SOURCING:-0}" -gt 0 ] || wat "$@"
|