1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-20 05:53:52 +01:00
zsh/Completion/Core/_normal
1999-04-15 18:05:38 +00:00

55 lines
1.1 KiB
Plaintext

#autoload
local comp cmd1 cmd2 pat val name
# Completing in command position? If not we set up `cmd1' and `cmd2' as
# two strings we have search in the completion definition arrays (e.g.
# a path and the last path name component).
if [[ $CONTEXT == command ]]; then
comp="$_comps[-command-]"
[[ -z "$comp" ]] || "$comp" "$@"
return
elif [[ "$COMMAND[1]" == '=' ]]; then
eval cmd1\=$COMMAND
cmd2="$COMMAND[2,-1]"
elif [[ "$COMMAND" == */* ]]; then
cmd1="$COMMAND"
cmd2="${COMMAND:t}"
else
cmd1="$COMMAND"
eval cmd2=$(whence -p $COMMAND)
fi
# See if there are any matching pattern completions.
for i in "$_patcomps[@]"; do
pat="${i% *}"
val="${i#* }"
if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
"$val" "$@"
if (( $+_compskip )); then
unset _compskip
return
fi
fi
done
# Now look up the two names in the normal completion array.
name="$cmd1"
comp="$_comps[$cmd1]"
if [[ -z "$comp" ]]; then
name="$cmd2"
comp="$_comps[$cmd2]"
fi
# And generate the matches, probably using default completion.
if [[ -z "$comp" ]]; then
name=-default-
comp="$_comps[-default-]"
fi
[[ -z "$comp" ]] || "$comp" "$@"