1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-27 16:50:58 +01:00

Merge of users/8863: which-command stuff.

This commit is contained in:
Paul Ackersviller 2007-04-29 02:06:43 +00:00
parent acc438a775
commit cedc5f8e1f
2 changed files with 54 additions and 0 deletions

View file

@ -867,6 +867,18 @@ example(zle -N insert-last-assignment smart-insert-last-word
zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*' zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
bindkey '\e=' insert-last-assignment) bindkey '\e=' insert-last-assignment)
) )
tindex(which-command)
item(tt(which-command))(
This function is a drop-in replacement for the builtin widget
tt(which-command). It has enhanced behaviour, in that it correctly
detects whether or not the command word needs to be expanded as an
alias; if so, it continues tracing the command word from the expanded
alias until it reaches the command that will be executed.
The style tt(whence) is available in the context tt(:zle:$WIDGET); this
may be set to an array to give the command and options that will be used to
investigate the command word found. The default is tt(whence -c).
)
enditem() enditem()
subsect(Styles) subsect(Styles)

View file

@ -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