about summary refs log tree commit diff
path: root/Completion/Base/_subscript
blob: 8038939121454285ca2eb4c5fda5f4c43ffa055d (plain) (blame)
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
#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