1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-20 05:53:52 +01:00
zsh/Completion/Base/_values

158 lines
3.5 KiB
Plaintext
Raw Normal View History

1999-09-06 11:16:29 +02:00
#autoload
2000-04-01 22:43:43 +02:00
local subopts opt usecc
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
subopts=()
while [[ "$1" = -(O*|C) ]]; do
case "$1" in
-C) usecc=yes; shift ;;
-O) subopts=( "${(@P)2}" ); shift 2 ;;
*) subopts=( "${(@P)1[3,-1]}" ); shift ;;
esac
done
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
if compvalues -i "$@"; then
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
local noargs args opts descr action expl sep subc
local oldcontext="$curcontext"
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
if ! compvalues -D descr action; then
1999-09-06 11:16:29 +02:00
_tags values || return 1
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
curcontext="${oldcontext%:*}:values"
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
compvalues -V noargs args opts
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
if [[ "$PREFIX" = *\=* ]]; then
local name
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
name="${PREFIX%%\=*}"
if compvalues -L "$name" descr action; then
IPREFIX="${IPREFIX}${name}="
PREFIX="${PREFIX#*\=}"
1999-09-06 11:16:29 +02:00
else
2000-04-01 22:43:43 +02:00
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 subc
curcontext="${oldcontext%:*}:$subc"
1999-09-06 11:16:29 +02:00
fi
2000-04-01 22:43:43 +02:00
else
compvalues -d descr
if [[ ${#noargs}+${#args}+${#opts} -ne 1 ]] && compvalues -s sep; then
sep=( "-qQS" "$sep" )
1999-09-06 11:16:29 +02:00
else
2000-04-01 22:43:43 +02:00
sep=()
1999-09-06 11:16:29 +02:00
fi
2000-04-01 22:43:43 +02:00
_describe "$descr" \
noargs "$sep[@]" -M 'r:|[_-]=* r:|=*' -- \
args -S= -M 'r:|[_-]=* r:|=*' -- \
opts -qS= -M 'r:|[_-]=* r:|=*'
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
curcontext="$oldcontext"
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
return
1999-09-06 11:16:29 +02:00
fi
else
2000-04-01 22:43:43 +02:00
compvalues -C subc
curcontext="${oldcontext%:*}:$subc"
1999-09-06 11:16:29 +02:00
fi
2000-04-01 22:43:43 +02:00
if ! _tags arguments; then
curcontext="$oldcontext"
return 1
1999-09-06 11:16:29 +02:00
fi
2000-04-01 22:43:43 +02:00
_description arguments expl "$descr"
1999-09-06 11:16:29 +02:00
# We add the separator character as a autoremovable suffix unless
# we have only one possible value left.
2000-04-01 22:43:43 +02:00
[[ ${#snames}+${#names}+${#onames} -ne 1 ]] && compvalues -s sep &&
1999-09-06 11:16:29 +02:00
expl=( "-qS$sep" "$expl[@]" )
if [[ "$action" = -\>* ]]; then
2000-04-01 22:43:43 +02:00
compvalues -v val_args
1999-09-06 11:16:29 +02:00
state="${${action[3,-1]##[ ]#}%%[ ]#}"
2000-04-01 22:43:43 +02:00
if [[ -n "$usecc" ]]; then
curcontext="${oldcontext%:*}:$subc"
else
context="$subc"
fi
1999-09-06 11:16:29 +02:00
compstate[restore]=''
return 1
else
2000-04-01 22:43:43 +02:00
typeset -A val_args
1999-09-06 11:16:29 +02:00
2000-04-01 22:43:43 +02:00
compvalues -v val_args
1999-09-06 11:16:29 +02:00
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]}" \)
2000-04-01 22:43:43 +02:00
_describe "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]"
1999-09-06 11:16:29 +02:00
elif [[ "$action" = \(*\) ]]; then
# Anything inside `(...)' is added directly.
2000-04-01 22:43:43 +02:00
_all_labels arguments expl "$descr" \
compadd "$subopts[@]" - ${=action[2,-2]}
1999-09-06 11:16:29 +02:00
elif [[ "$action" = \{*\} ]]; then
# A string in braces is evaluated.
2000-04-01 22:43:43 +02:00
while _next_label arguments expl "$descr"; do
eval "$action[2,-2]"
done
1999-09-06 11:16:29 +02:00
elif [[ "$action" = \ * ]]; then
# If the action starts with a space, we just call it.
2000-04-01 22:43:43 +02:00
eval "action=( $action )"
while _next_label arguments expl "$descr"; do
"$action[@]"
done
1999-09-06 11:16:29 +02:00
else
# Otherwise we call it with the description-arguments built above.
2000-04-01 22:43:43 +02:00
eval "action=( $action )"
while _next_label arguments expl "$descr"; do
"$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}"
done
1999-09-06 11:16:29 +02:00
fi
fi
2000-04-01 22:43:43 +02:00
curcontext="$oldcontext"
[[ nm -ne "$compstate[nmatches]" ]]
else
curcontext="$oldcontext"
return 1;
fi