summary refs log tree commit diff
path: root/Completion/Builtins/_vars
blob: 501e37b4f170ba388092350eba10dd884fe825d6 (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
#compdef getopts unset vared

# This will handle completion of keys of associative arrays, e.g. at
# `vared foo[<TAB>'.

local ret=1

if [[ $PREFIX = *\[* ]]; then
  local var=${PREFIX%%\[*}
  local elt="${PREFIX#*\]}${SUFFIX%\]}"
  local addclose

  compset -p $(( ${#var} + 1 ))
  if ! compset -S \]; then
    addclose=(-S "${${QIPREFIX:+]}:-\]}")
  fi
  if [[ ${(tP)var} = assoc* ]]; then
    local expl

    _wanted -C subscript association-keys expl 'association key' \
        compadd $addclose -k "$var"
  fi
else
  _parameters -g '^a*' "$@" && ret=0
  
  if compset -S '\[*'; then
    set - -S "" "$@"
  else
    set - -qS"${${QIPREFIX:+[}:-\[}" "$@"
  fi
  _parameters -g 'a*' "$@" && ret=0
  return ret
fi