about summary refs log tree commit diff
path: root/Completion/Builtins/_compdef
blob: 772c6b90d39f96a1a9ed7b0f44c5aa709e69d140 (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
#compdef compdef

local state line expl list disp

_arguments -C -s \
  '(-d)-a[make function autoloadable]' \
  '(-d -p -P)-n[leave existing definitions intact]' \
  '(-a -n -p -P -k -K)-d[delete]:*:completed command:->ccom' \
  '(-n -d -P -k -K)-p[completion for command matching pattern]:completion function:->cfun:pattern' \
  '(-n -d -p -k -K)-P[as -p for commands without own completion]:completion function:->cfun:pattern' \
  '(-d -p -P -K)-k[define widget and key binding]:completion function:->cfun:widget name::style:->style:*:key' \
  '(-d -p -P -k)-K[define multiple widgets based on function]:completion function:->cfun:widget name::style:->style:*:key' \
  '1:completion function:->cfun' \
  '2:commands:_command_names'
  

case $state in
  ccom)
    _wanted commands expl 'completed command' &&
        compadd "$expl[@]" - ${(k)_comps}
  ;;
  cfun)
    if _wanted functions expl 'completion function'; then
      list=( ${^fpath:/.}/_(|*[^~])(N:t) )
      if zstyle -T ":completion:${curcontext}" prefix-hidden; then
        disp=( ${list[@]#_} )
        compadd "$expl[@]" -d disp - "$list[@]"
      else
        compadd "$expl[@]" - "$list[@]"
      fi
    fi
  ;;
  style)
    _wanted widgetstyle expl 'widget style' &&
        compadd complete-word delete-char-or-list expand-or-complete \
        expand-or-complete-prefix list-choices menu-complete \
        menu-expand-or-complete reverse-menu-complete
  ;;
esac