about summary refs log tree commit diff
path: root/Completion/Base/_subscript
blob: c5c6ca7e9ba0cfe2ec87f77216834d3809243642 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#compdef -subscript-

local expl

if [[ "$PREFIX" = :* ]]; then
  _tags any char-classes || return 1

  _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
  _tags any association-keys || return 1

  _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 ret=1 disp

  _tags any indexes parameters

  while _tags; do
    if _requested indexes; then
      _description -V expl 'array index'
      ind=( {1..${#${(P)${compstate[parameter]}}}} )
      if _style indexes description yes; then
        list=()
        for i in "$ind[@]"; do
          [[ "$i" = ${PREFIX}*${SUFFIX} ]] &&
              list=( "$list[@]" 
	             "${i}:$(print -D ${(P)${compstate[parameter]}[$i]})" )
        done
        compdisplay list ' -- ' "$list[@]"
	disp=( -d list)
      else
        disp=()
      fi

      if [[ "$RBUFFER" = \]* ]]; then
        compadd "$expl[@]" -S '' "$disp[@]" - "$ind[@]" && ret=0
      else
        compadd "$expl[@]" -S ']' "$disp[@]" - "$ind[@]" && ret=0
      fi
    fi
    _requested parameters && _parameters && ret=0

    (( ret )) || return 0
  done

  return 1
else
  _compalso -math-
fi