about summary refs log tree commit diff
path: root/Completion/Zsh/Context/_value
blob: 9d0acaa0eb4690ed426b2a2278388bb5033834f7 (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
57
#compdef -value- -array-value- -T values -default-

# You can customize completion for different parameters by writing
# functions with the tag-line `#compdef -T value <name>'.
# The function searches for the strings `<param-name>:<param-type>'
# and `<param-name>'. If the line contains a command (as in `make foo=<TAB>')
# the string `<command>:<param-name>:<param-type>' is also searched for.

if [[ "$service" != -default- ]]; then
  local strs type

  type="${(Pt)compstate[parameter]}"

  if [[ -z "$type" ]]; then
    if [[ "$compstate[parameter]" = *-* ]]; then
      type=association-value
    elif [[ "$compstate[context]" = value ]]; then
      type=scalar
    else
      type=array
    fi
  fi

  strs=( "${compstate[parameter]}:$type" "$compstate[parameter]" )

  if [[ "$compstate[context]" != *value && -n "$_comp_command1" ]]; then
    strs=( "${_comp_command1}:$^strs[@]" "$strs[@]" )
    [[ -n "$_comp_command2" ]] &&
        strs=( "${_comp_command2}:${(@)^strs[-2,-1]}" "$strs[@]" )
  fi

  _dispatch -d values "$strs[@]"
else
  if [[ "$compstate[parameter]" != *-* &&
        "$compstate[context]" = *value &&
        "${(Pt)${compstate[parameter]}}" = assoc* ]]; then
    if (( CURRENT & 1 )); then
      _wanted association-keys expl 'association key' \
          compadd -k "$compstate[parameter]"
    else
      compstate[parameter]="${compstate[parameter]}-${words[CURRENT-1]}"
      _value "$@"
    fi
  else
    local pats

    if { zstyle -a ":completion:${curcontext}:" assign-list pats &&
         [[ "$compstate[parameter]" = (${(j:|:)~pats}) ]] } ||
       [[ "$PREFIX$SUFFIX" = *:* ]]; then
      compset -P '*:'
      compset -S ':*'
      _default -r '\-\n\t /:' "$@"
    else
      _default "$@"
    fi
  fi
fi