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

local state line expl list disp curcontext="$curcontext" ret=1
typeset -A opt_args

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

if [[ $state = multi ]]; then
  case $(( CURRENT % 3 )) in
  0) _message key
     return 1;;
  1) state=cfun;;
  2) state=style;;
  esac
fi

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

return ret