about summary refs log tree commit diff
path: root/Completion/Base/Utility/_describe
blob: 45b8c17d634453aeb39dc3c1559aadec46496e28 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#autoload

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

local _opt _expl _tmps _tmpd _tmph _tmpmd _tmpms _tmpmh
local _type=values _descr _ret=1 _showd _nm _hide _args _grp

# Get the option.

if [[ "$1" = -o ]]; then
  _type=options
  shift
elif [[ "$1" = -t ]]; then
  _type="$2"
  shift 2
elif [[ "$1" = -t* ]]; then
  _type="${1[3,-1]}"
  shift
fi

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

zstyle -T ":completion:${curcontext}:$_type" verbose && _showd=yes

if zstyle -T ":completion:${curcontext}:$_type" list-grouped; then
  local _argv _new _strs _mats _opts _i=2

  _argv=( "$@" )
  _grp=(-g)
  _new=( "$1" )
  shift

  while (( $# )); do

    _strs="_a_$_i"
    eval local "_a_$_i;_a_$_i"'=( "${'$1'[@]}" )'
    _argv[_i]="_a_$_i"
    shift
    (( _i++ ))

    if [[ "$1" = (|-*) ]]; then
      _mats=
    else
      _matss="_a_$_i"
      eval local "_a_$_i;_a_$_i"'=( "${'$1'[@]}" )'
      _argv[_i]="_a_$_i"
      shift
      (( _i++ ))
    fi

    _opts=( "${(@)argv[1,(i)--]:#--}" )
    shift "$#_opts"
    (( _i += $#_opts ))
    if [[ $1 == -- ]]; then
      shift
      (( _i++ ))
    fi

    if [[ -n $_mats ]]; then
      compadd "$_opts[@]" -O $_strs -D $_mats -a $_strs
    else
      compadd "$_opts[@]" -O $_strs -a $_strs
    fi
  done

  set - "$_argv[@]"
else
  _grp=()
fi

_descr="$1"
shift

[[ "$_type" = options ]] &&
    zstyle -t ":completion:${curcontext}:options" prefix-hidden && _hide=yes

_tags "$_type"
while _tags; do
  while _next_label "$_type" _expl "$_descr"; do

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

    while compdescribe -g _args _tmpd _tmpmd _tmph _tmpmh _tmps _tmpms; do

      # See if we should remove the option prefix characters.

      if [[ -n "$_hide" ]]; then
        if [[ "$PREFIX" = --* ]]; then
          _tmpd=( "${(@)_tmpd#--}" )
          _tmph=( "${(@)_tmph#--}" )
          _tmps=( "${(@)_tmps#--}" )
        elif [[ "$PREFIX" = [-+]* ]]; then
          _tmpd=( "${(@)_tmpd#[-+]}" )
          _tmph=( "${(@)_tmph#[-+]}" )
          _tmps=( "${(@)_tmps#[-+]}" )
        fi
      fi

      compadd "$_args[@]" "$_expl[@]" -ld _tmpd -a _tmpmd && _ret=0
      compadd -n "$_args[@]" "$_expl[@]" -ld _tmph -a _tmpmh && _ret=0
      compadd "$_args[@]" "$_expl[@]" -d _tmps  -a _tmpms && _ret=0
    done
  done
  (( _ret )) || return 0
done

return 1