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

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

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

cmd="$words[1]"

# Get the options.

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

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

_tags -c "$cmd" "$type" || return 1

_style "$type" describe && showd=yes

_description expl "$1"
shift

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

[[ "$type" = option ]] && _style 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