about summary refs log tree commit diff
path: root/Completion/Base/_value
blob: 723285233e2fabf3189928ab496445b4f6456b0a (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
#compdef -value- -array-value-

_value () {
  # You can customize completion for different parameters by writing a
  # function `_value:<name>'.

  if (( $+functions[_value:$compstate[parameter]] )); then
    "_value:$compstate[parameter]" "$@"
  elif [[ "$compstate[parameter]" != *-* &&
          "${(Pt)${compstate[parameter]}}" = assoc* ]]; then
    if (( CURRENT & 1 )); then
      _wanted association-keys expl 'association key' \
          compadd - "${(@kP)${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 -qS: "$@"
    else
      _default "$@"
    fi
  fi
}

_value:CPPFLAGS () {
  compset -q
  if compset -P '-I'; then
    _files -/ "$@"
  else
    _default "$@"
  fi
}

_value:LDFLAGS () {
  compset -q
  if compset -P '-L'; then
    _files -/ "$@"
  elif compset -P '-R'; then
    compset -P '*:'
    compset -S ':*'
    _files -/ -S/ -r ' :' "$@"
  else
    _default "$@"
  fi
}

_value "$@"