diff options
author | Paul Ackersviller <packersv@users.sourceforge.net> | 2007-04-29 02:06:43 +0000 |
---|---|---|
committer | Paul Ackersviller <packersv@users.sourceforge.net> | 2007-04-29 02:06:43 +0000 |
commit | cedc5f8e1f8916202da403a08b77600a7271fbe3 (patch) | |
tree | 6e2f580e4f0d4d28c50120996e2f970cf57deb30 /Functions | |
parent | acc438a775cfe547f55e2fb2e705567d661b323b (diff) | |
download | zsh-cedc5f8e1f8916202da403a08b77600a7271fbe3.tar.gz zsh-cedc5f8e1f8916202da403a08b77600a7271fbe3.tar.xz zsh-cedc5f8e1f8916202da403a08b77600a7271fbe3.zip |
Merge of users/8863: which-command stuff.
Diffstat (limited to 'Functions')
-rw-r--r-- | Functions/Zle/which-command | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Functions/Zle/which-command b/Functions/Zle/which-command new file mode 100644 index 000000000..6e15c32a4 --- /dev/null +++ b/Functions/Zle/which-command @@ -0,0 +1,42 @@ +zmodload -i zsh/parameter zsh/zutil + +zle -I + +local -a whencecmd wds + +# Set the whence style to your favourite function +# (but NOT which-command!) +zstyle -a :zle:$WIDGET whence whencecmd || whencecmd=(whence -c --) + +wds=(${(z)LBUFFER}) +local wd barewd +local -A seen + +while true; do + wd=${wds[1]} + barewd=${(Q)wd} + + if [[ $barewd != $wd || -n $seen[$barewd] ]]; then + # quoted or already expanded, see if original word is an alias... + if [[ -z $seen[$barewd] && -n $aliases[$wd] ]]; then + # yes, so we need to decode that, with no extra expansion... + $whencecmd $wd + seen[$wd]=1 + wds=(${(z)aliases[$wd]}) + continue + else + # use unquoted word, don't expand alias + (unalias -- $barewd 2>/dev/null; $whencecmd $barewd) + fi + else + # turn on globsubst for =ls etc. + $whencecmd ${~barewd} + if [[ -n $aliases[$barewd] && -z $seen[$barewd] ]]; then + # Recursively expand aliases + seen[$barewd]=1 + wds=(${(z)aliases[$barewd]}) + continue + fi + fi + break +done |