mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-04 22:51:42 +02:00
117 lines
2.5 KiB
Text
117 lines
2.5 KiB
Text
#autoload
|
|
|
|
setopt localoptions extendedglob
|
|
|
|
if compvalues -i "$@"; then
|
|
|
|
local noargs args opts descr action expl sep
|
|
|
|
if ! compvalues -D descr action; then
|
|
compvalues -V noargs args opts
|
|
|
|
if [[ "$PREFIX" = *\=* ]]; then
|
|
local name
|
|
|
|
name="${PREFIX%%\=*}"
|
|
if compvalues -L "$name" descr action; then
|
|
IPREFIX="${IPREFIX}${name}="
|
|
PREFIX="${PREFIX#*\=}"
|
|
else
|
|
local prefix suffix
|
|
|
|
prefix="${PREFIX#*\=}"
|
|
suffix="$SUFFIX"
|
|
PREFIX="$name"
|
|
SUFFIX=''
|
|
args=( "$args[@]" "$opts[@]" )
|
|
compadd -M 'r:|[_-]=* r:|=*' -D args - "${(@)args[@]%%:*}"
|
|
|
|
[[ $#args -ne 1 ]] && return 1
|
|
|
|
PREFIX="$prefix"
|
|
SUFFIX="$suffix"
|
|
IPREFIX="${IPREFIX}${args[1]%%:*}="
|
|
compvalues -L "${args[1]%%:*}" descr action
|
|
fi
|
|
else
|
|
compvalues -d descr
|
|
if [[ ${#noargs}+${#args}+${#opts} -ne 1 ]] && compvalues -s sep; then
|
|
sep=( "-qQS$sep" )
|
|
else
|
|
sep=()
|
|
fi
|
|
|
|
_describe "$descr" \
|
|
noargs "$sep[@]" -M 'r:|[_-]=* r:|=*' -- \
|
|
args -S= -M 'r:|[_-]=* r:|=*' -- \
|
|
opts -qS= -M 'r:|[_-]=* r:|=*'
|
|
|
|
return
|
|
fi
|
|
fi
|
|
|
|
_description expl "$descr"
|
|
|
|
# We add the separator character as a autoremovable suffix unless
|
|
# we have only one possible value left.
|
|
|
|
[[ ${#snames}+${#names}+${#onames} -ne 1 ]] && compvalues -s sep &&
|
|
expl=( "-qS$sep" "$expl[@]" )
|
|
|
|
if [[ "$action" = -\>* ]]; then
|
|
compvalues -v val_args
|
|
state="${${action[3,-1]##[ ]#}%%[ ]#}"
|
|
compstate[restore]=''
|
|
return 1
|
|
else
|
|
typeset -A val_args
|
|
|
|
compvalues -v val_args
|
|
|
|
if [[ "$action" = \ # ]]; then
|
|
|
|
# An empty action means that we should just display a message.
|
|
|
|
_message "$descr"
|
|
return 1
|
|
|
|
elif [[ "$action" = \(\(*\)\) ]]; then
|
|
local ws
|
|
|
|
# ((...)) contains literal strings with descriptions.
|
|
|
|
eval ws\=\( "${action[3,-3]}" \)
|
|
|
|
_describe "$descr" ws -M 'r:|[_-]=* r:|=*'
|
|
|
|
elif [[ "$action" = \(*\) ]]; then
|
|
|
|
# Anything inside `(...)' is added directly.
|
|
|
|
compadd "$expl[@]" - ${=action[2,-2]}
|
|
elif [[ "$action" = \{*\} ]]; then
|
|
|
|
# A string in braces is evaluated.
|
|
|
|
eval "$action[2,-2]"
|
|
|
|
elif [[ "$action" = \ * ]]; then
|
|
|
|
# If the action starts with a space, we just call it.
|
|
|
|
${(e)=~action}
|
|
else
|
|
|
|
# Otherwise we call it with the description-arguments built above.
|
|
|
|
action=( $=action )
|
|
${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]}
|
|
fi
|
|
fi
|
|
|
|
[[ nm -ne "$compstate[nmatches]" ]]
|
|
return
|
|
|
|
else
|
|
return 1;
|
|
fi
|