1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#autoload
# ### Note: Calling this function twice during one completion operation, such
# ### that in each call there exists a pair of items having the same description
# ### as each other, and the two calls specify the same $_type, currently leads
# ### to garbled output; see workers/35229 (May 2015) and its thread (which also
# ### discusses at least two other issues, that may or may not be related to
# ### this one).
# This can be used to add options or values with descriptions as matches.
local _opt _expl _tmpm _tmpd _mlen _noprefix
local _type=values _descr _ret=1 _showd _nm _hide _args _grp _sep
local csl="$compstate[list]" csl2
local _oargv _argv _new _strs _mats _opts _i _try=0
local OPTIND OPTARG
local -a _jvx12
# Get the option.
while getopts "oOt:12JVx" _opt; do
case $_opt in
(o)
_type=options;;
(O)
_type=options
_noprefix=1
;;
(t)
_type="$OPTARG"
;;
(1|2|J|V|x)
_jvx12+=(-$_opt)
esac
done
shift $(( OPTIND - 1 ))
unset _opt
[[ "$_type$_noprefix" = options && ! -prefix [-+]* ]] && \
zstyle -T ":completion:${curcontext}:options" prefix-needed &&
return 1
# Do the tests. `showd' is set if the descriptions should be shown.
zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes
zstyle -s ":completion:${curcontext}:$_type" list-separator _sep || _sep=--
zstyle -s ":completion:${curcontext}:$_type" max-matches-width _mlen ||
_mlen=$((COLUMNS/2))
_descr="$1"
shift
if [[ -n "$_showd" ]] &&
zstyle -T ":completion:${curcontext}:$_type" list-grouped; then
_oargv=( "$@" )
_grp=(-g)
else
_grp=()
fi
[[ "$_type" = options ]] &&
zstyle -t ":completion:${curcontext}:options" prefix-hidden &&
_hide="${(M)PREFIX##(--|[-+])}"
_tags "$_type"
while _tags; do
while _next_label $_jvx12 "$_type" _expl "$_descr"; do
if (( $#_grp )); then
set -- "$_oargv[@]"
_argv=( "$_oargv[@]" )
_i=1
(( _try++ ))
while (( $# )); do
_strs="_a_$_try$_i"
if [[ "$1" = \(*\) ]]; then
eval local "_a_$_try$_i;_a_$_try$_i"'='$1
else
eval local "_a_$_try$_i;_a_$_try$_i"'=( "${'$1'[@]}" )'
fi
_argv[_i]="_a_$_try$_i"
shift
(( _i++ ))
if [[ "$1" = (|-*) ]]; then
_mats=
else
_mats="_a_$_try$_i"
if [[ "$1" = \(*\) ]]; then
eval local "_a_$_try$_i;_a_$_try$_i"'='$1
else
eval local "_a_$_try$_i;_a_$_try$_i"'=( "${'$1'[@]}" )'
fi
_argv[_i]="_a_$_try$_i"
shift
(( _i++ ))
fi
_opts=( "${(@)argv[1,(i)--]:#--}" )
shift "$#_opts"
(( _i += $#_opts ))
if [[ $1 == -- ]]; then
shift
(( _i++ ))
fi
if [[ -n $_mats ]]; then
compadd "$_opts[@]" -2 -o nosort "${_expl[@]}" -D $_strs -O $_mats - \
"${(@)${(@M)${(@P)_mats}##([^:\\]|\\?)##}//\\(#b)(?)/$match[1]}"
else
compadd "$_opts[@]" -2 -o nosort "${_expl[@]}" -D $_strs - \
"${(@)${(@M)${(@P)_strs}##([^:\\]|\\?)##}//\\(#b)(?)/$match[1]}"
fi
done
set - "$_argv[@]"
fi
if [[ -n "$_showd" ]]; then
compdescribe -I "$_hide" "$_mlen" "$_sep " _expl "$_grp[@]" "$@"
else
compdescribe -i "$_hide" "$_mlen" "$@"
fi
compstate[list]="$csl"
while compdescribe -g csl2 _args _tmpm _tmpd; do
compstate[list]="$csl $csl2"
[[ -n "$csl2" ]] && compstate[list]="${compstate[list]:s/rows//}"
compadd "$_args[@]" -d _tmpd -a _tmpm && _ret=0
done
done
(( _ret )) || return 0
done
return 1
|