about summary refs log tree commit diff
path: root/Completion/Commands/_complete_help
blob: cfc922df5a7405598a31a3a1fbb9171f35de5bf7 (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
#compdef -k complete-word \C-xh

_complete_help() {
  local _sort_tags=_help_sort_tags text i j k
  typeset -A help_funcs help_tags help_sfuncs help_styles

  compadd() { return 1 }
  zstyle() {
    local _f="${${(@)${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"

    [[ -z "$_f" ]] && _f="${${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}"

    if [[ "$help_sfuncs[$2]" != *${_f}* ||
          "$help_styles[${2}${_f}]" != *${3}* ]]; then
      [[ "$help_sfuncs[$2]" != *${_f}* ]] &&
          help_sfuncs[$2]="${help_sfuncs[$2]}:${_f}"
      local _t

      case "$1" in
      -s) _t='[string] ';;
      -a) _t='[array]  ';;
      -h) _t='[assoc]  ';;
      *)  _t='[boolean]';;
      esac
      help_styles[${2}${_f}]="${help_styles[${2}${_f}]},${_t} ${3}:${_f}"
    fi
    builtin zstyle "$@"
  }

  _main_complete

  unfunction compadd zstyle

  for i in "${(@ok)help_funcs}"; do
    text="${text}
tags in context :completion:${i}:"
    tmp=()
    for j in "${(@s.:.)help_funcs[$i][2,-1]}"; do
      tmp=( "$tmp[@]" "${(@s.,.)help_tags[${i}${j}][2,-1]}" )
    done
    zformat -a tmp '  (' "$tmp[@]"
    tmp=( '
    '${^tmp}')' )
    text="${text}${tmp}"
  done

  text="$text
"
  for i in "${(@ok)help_sfuncs}"; do
    text="${text}
styles in context ${i}"
    tmp=()
    for j in "${(@s.:.)help_sfuncs[$i][2,-1]}"; do
      tmp=( "$tmp[@]" "${(@s.,.)help_styles[${i}${j}][2,-1]}" )
    done
    zformat -a tmp '  (' "$tmp[@]"
    tmp=( '
    '${^tmp}')' )
    text="${text}${tmp}"
  done

  compstate[list]='list force'
  compstate[insert]=''

  compadd -UX "$text[2,-1]" -n ''
}

_help_sort_tags() {
  local f="${${(@)${(@)funcstack[3,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"

  if [[ "$help_funcs[$curcontext]" != *${f}* ||
        "$help_tags[${curcontext}${f}]" != *(${(j:|:)~argv})* ]]; then
    [[ "$help_funcs[$curcontext]" != *${f}* ]] &&
        help_funcs[$curcontext]="${help_funcs[$curcontext]}:${f}"
    help_tags[${curcontext}${f}]="${help_tags[${curcontext}${f}]},${argv}:${f}"
    comptry "$@"
  fi
}

_complete_help "$@"