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

93 lines
2.7 KiB
Plaintext
Raw Normal View History

2001-04-02 13:24:32 +02:00
#compdef -subscript-
2001-05-05 01:00:18 +02:00
local expl ind osuf=']' flags
2001-04-02 13:24:32 +02:00
if [[ "$1" = -q ]]; then
osuf='] '
compquote osuf
shift
fi
2001-05-05 01:00:18 +02:00
compset -P '\([^\)]##\)' # remove subscript flags
2001-04-02 13:24:32 +02:00
if [[ "$PREFIX" = :* ]]; then
_wanted characters expl 'character class' \
compadd -p: -S ':]' alnum alpha blank cntrl digit graph \
lower print punct space upper xdigit
2001-05-05 01:00:18 +02:00
elif compset -P '\('; then
compset -S '\)*'
case ${(Pt)${compstate[parameter]}} in
assoc*) flags=(
2001-05-05 22:11:59 +02:00
'(R k K i I)r[any one value matched by subscript as pattern]'
'(r k K i I)R[all values matched by subscript as pattern]'
'(r R K i I)k[any one value where subscript matched by key as pattern]'
'(r R k i I)K[all values where subscript matched by key as pattern]'
'(r R k K I)i[any one key matched by subscript as pattern]'
'(r R k K i)I[all keys matched by subscript as pattern]'
2001-05-05 01:00:18 +02:00
);;
(|scalar*)) flags=(
'w[make subscripting work on words of scalar]'
's[specify word separator]'
'p[recognise escape sequences in subsequent s flag]'
);&
array*) flags=($flags
2001-05-05 22:11:59 +02:00
'n[Nth lowest/highest index with i/I/r/R flag]'
2001-05-05 01:00:18 +02:00
'b[begin with specified element]'
2001-05-05 22:11:59 +02:00
'(r R k K i)I[highest index of value matched by subscript]'
'(r R k K I)i[lowest index of value matched by subscript]'
'(r k K i I)R[value matched by subscript at highest index]'
'(R k K i I)r[value matched by subscript at lowest index]'
2001-05-05 01:00:18 +02:00
);;
esac
_values -s '' 'subscript flags' $flags
2001-04-02 13:24:32 +02:00
elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
local suf
[[ "$RBUFFER" != (|\\)\]* ]] && suf="$osuf"
_wanted association-keys expl 'association key' \
compadd -S "$suf" -k "$compstate[parameter]"
elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
local list i j ret=1 disp
_tags indexes parameters
while _tags; do
if _requested indexes; then
ind=( {1..${#${(P)${compstate[parameter]}}}} )
if zstyle -T ":completion:${curcontext}:indexes" verbose; then
list=()
for i in "$ind[@]"; do
if [[ "$i" = ${PREFIX}*${SUFFIX} ]]; then
list=( "$list[@]"
"${i}:$(print -D ${(P)${compstate[parameter]}[$i]})" )
else
list=( "$list[@]" '' )
fi
done
zformat -a list ' -- ' "$list[@]"
disp=( -d list)
else
disp=()
fi
if [[ "$RBUFFER" = (|\\)\]* ]]; then
_all_labels -V indexes expl 'array index' \
compadd -S '' "$disp[@]" -a ind && ret=0
else
_all_labels -V indexes expl 'array index' \
compadd -S "$osuf" "$disp[@]" -a ind && ret=0
fi
fi
_requested parameters && _parameters && ret=0
(( ret )) || return 0
done
return 1
else
_contexts -math-
fi