about summary refs log tree commit diff
path: root/Completion/Base/_describe
blob: ddd35f0e743fed7525a1020cb9db3b78a8124f18 (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
58
#autoload

# This can be used to add options or values with descriptions as matches.

local cmd func opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide
local tags type=value

cmd="$words[1]"
func="$funcstack[2]"

# Get the options.

while getopts 'oc:f:' opt; do
  if [[ "$opt" = o ]]; then
    type=option
  elif [[ "$opt" = f ]]; then
    func="$OPTARG"
  else
    cmd="$OPTARG"
  fi
done
shift OPTIND-1

# Do the tests. `showd' is set if the descriptions should be shown.

_tags -i -c "$cmd" -f "$func" "$type" || return 1

[[ "$tags" = *:${type}\[*describe*\]* ]] && showd=yes

_description expl "$1"
shift

if [[ -n "$showd" ]]; then
  compdescribe -I ' -- ' "$@"
else
  compdescribe -i "$@"
fi

[[ "$type" = option && "$tags" = *:option\[*hide*\]* ]] && hide=yes

while compdescribe -g args tmpd tmpmd tmps tmpms; do

  # See if we should remove the option prefix characters.

  if [[ -n "$hide" ]]; then
    if [[ "$PREFIX" = --* ]]; then
      tmpd=( "${(@)tmpd#--}" )
      tmps=( "${(@)tmps#--}" )
    elif [[ "$PREFIX" = [-+]* ]]; then
      tmpd=( "${(@)tmpd#[-+]}" )
      tmps=( "${(@)tmps#[-+]}" )
    fi
  fi
  compadd "$args[@]" "$expl[@]" -ld tmpd - "$tmpmd[@]" && ret=0
  compadd "$args[@]" "$expl[@]" -d tmps - "$tmpms[@]" && ret=0
done

return ret