-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwat
executable file
·39 lines (37 loc) · 1.16 KB
/
wat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env zsh
# compat: -ash -bash -dash -hush -ksh -mksh -oksh -osh -posh -yash +zsh
# wat - a better and recursive which/whence
# via: https://leahneukirchen.org/dotfiles/tools.html
wat() { ### @-
### wat — a better and recursive which/whence. for zsh only.
###
### written by [leah2.](https://leahneukirchen.org/)
( # constrain unalias
local cmd=
for cmd; do
if (( $+aliases[$cmd] )); then
printf '%s: aliased to %s\n' $cmd $aliases[$cmd]
local -a words=(${${(z)aliases[$cmd]}:#(*=*|rlwrap|nocorrect|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
)
}
[ -n "${preload+-}" ] || wat "$@"