about summary refs log tree commit diff
path: root/Completion/Base/_describe
blob: 181ccbfcb99165ea1eb2539430fe4e2e260e8a25 (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 _args
local _type=values

_cmd="$words[1]"

# Get the options.

while getopts 'oc:' _opt; do
  if [[ "$_opt" = o ]]; then
    _type=options
  else
    _cmd="$OPTARG"
  fi
done
shift OPTIND-1

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

_tags "$_type" || return 1

_style "$_type" description && _showd=yes

_description _expl "$1"
shift

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

[[ "$_type" = options ]] && _style options prefix-hidden && _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