2001-04-02 13:10:44 +02:00
|
|
|
#autoload
|
|
|
|
|
|
|
|
# This can be used to add options or values with descriptions as matches.
|
|
|
|
|
2001-07-25 10:52:34 +02:00
|
|
|
local _opt _expl _tmpm _tmpd
|
|
|
|
local _type=values _descr _ret=1 _showd _nm _hide _args _grp _sep
|
|
|
|
local csl="$compstate[list]" csl2
|
2001-04-02 13:10:44 +02:00
|
|
|
|
|
|
|
# Get the option.
|
|
|
|
|
|
|
|
if [[ "$1" = -o ]]; then
|
|
|
|
_type=options
|
|
|
|
shift
|
|
|
|
elif [[ "$1" = -t ]]; then
|
|
|
|
_type="$2"
|
|
|
|
shift 2
|
|
|
|
elif [[ "$1" = -t* ]]; then
|
|
|
|
_type="${1[3,-1]}"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Do the tests. `showd' is set if the descriptions should be shown.
|
|
|
|
|
|
|
|
zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes
|
2001-07-19 10:40:36 +02:00
|
|
|
|
2001-07-18 15:10:07 +02:00
|
|
|
if zstyle -T ":completion:${curcontext}:$_type" list-grouped; then
|
2001-07-19 10:40:36 +02:00
|
|
|
local _argv _new _strs _mats _opts _i=2
|
|
|
|
|
|
|
|
_argv=( "$@" )
|
2001-07-18 15:10:07 +02:00
|
|
|
_grp=(-g)
|
2001-07-25 10:52:34 +02:00
|
|
|
_sep='-- '
|
2001-07-19 10:40:36 +02:00
|
|
|
_new=( "$1" )
|
|
|
|
shift
|
|
|
|
|
|
|
|
while (( $# )); do
|
|
|
|
|
|
|
|
_strs="_a_$_i"
|
|
|
|
eval local "_a_$_i;_a_$_i"'=( "${'$1'[@]}" )'
|
|
|
|
_argv[_i]="_a_$_i"
|
|
|
|
shift
|
|
|
|
(( _i++ ))
|
|
|
|
|
|
|
|
if [[ "$1" = (|-*) ]]; then
|
|
|
|
_mats=
|
|
|
|
else
|
|
|
|
_matss="_a_$_i"
|
|
|
|
eval local "_a_$_i;_a_$_i"'=( "${'$1'[@]}" )'
|
|
|
|
_argv[_i]="_a_$_i"
|
|
|
|
shift
|
|
|
|
(( _i++ ))
|
|
|
|
fi
|
|
|
|
|
|
|
|
_opts=( "${(@)argv[1,(i)--]:#--}" )
|
|
|
|
shift "$#_opts"
|
|
|
|
(( _i += $#_opts ))
|
|
|
|
if [[ $1 == -- ]]; then
|
|
|
|
shift
|
|
|
|
(( _i++ ))
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $_mats ]]; then
|
|
|
|
compadd "$_opts[@]" -O $_strs -D $_mats -a $_strs
|
|
|
|
else
|
|
|
|
compadd "$_opts[@]" -O $_strs -a $_strs
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
set - "$_argv[@]"
|
2001-07-18 15:10:07 +02:00
|
|
|
else
|
|
|
|
_grp=()
|
2001-07-25 10:52:34 +02:00
|
|
|
_sep=' -- '
|
2001-07-18 15:10:07 +02:00
|
|
|
fi
|
2001-04-02 13:10:44 +02:00
|
|
|
|
|
|
|
_descr="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
[[ "$_type" = options ]] &&
|
2001-07-25 10:52:34 +02:00
|
|
|
zstyle -t ":completion:${curcontext}:options" prefix-hidden &&
|
|
|
|
_hide="${(M)PREFIX##(--|[-+])}"
|
2001-04-02 13:10:44 +02:00
|
|
|
|
|
|
|
_tags "$_type"
|
|
|
|
while _tags; do
|
|
|
|
while _next_label "$_type" _expl "$_descr"; do
|
|
|
|
|
|
|
|
if [[ -n "$_showd" ]]; then
|
2001-07-25 10:52:34 +02:00
|
|
|
compdescribe -I "$_hide" "$_sep" _expl "$_grp[@]" "$@"
|
2001-04-02 13:10:44 +02:00
|
|
|
else
|
2001-07-25 10:52:34 +02:00
|
|
|
compdescribe -i "$_hide" "$@"
|
2001-04-02 13:10:44 +02:00
|
|
|
fi
|
|
|
|
|
2001-07-25 10:52:34 +02:00
|
|
|
compstate[list]="$csl"
|
|
|
|
|
|
|
|
while compdescribe -g csl2 _args _tmpm _tmpd; do
|
|
|
|
|
|
|
|
compstate[list]="$csl $csl2"
|
|
|
|
|
|
|
|
compadd "$_args[@]" -d _tmpd -a _tmpm && _ret=0
|
2001-04-02 13:10:44 +02:00
|
|
|
done
|
|
|
|
done
|
|
|
|
(( _ret )) || return 0
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|