1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-20 03:51:07 +02:00
zsh/Completion/Base/_subscript
1999-09-15 14:35:16 +00:00

35 lines
1 KiB
Text

#compdef -subscript-
local expl
if [[ "$PREFIX" = :* ]]; then
_description expl 'character class'
compadd "$expl[@]" -p: -S ':]' alnum alpha blank cntrl digit graph \
lower print punct space upper xdigit
elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
_description expl 'association key'
if [[ "$RBUFFER" = \]* ]]; then
compadd "$expl[@]" -S '' - "${(@kP)${compstate[parameter]}}"
else
compadd "$expl[@]" -S ']' - "${(@kP)${compstate[parameter]}}"
fi
elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
local list i j
_description expl 'array index'
ind=( {1..${#${(P)${compstate[parameter]}}}} )
list=()
for i in "$ind[@]"; do
[[ "$i" = ${PREFIX}*${SUFFIX} ]] &&
list=( "$list[@]"
"${(r:4:: ::):)i} $(print -D ${(P)${compstate[parameter]}[$i]})" )
done
if [[ "$RBUFFER" = \]* ]]; then
compadd "$expl[@]" -S '' -V default -d list - "$ind[@]"
else
compadd "$expl[@]" -S ']' -V default -d list - "$ind[@]"
fi
else
_compalso -math-
fi