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

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

args2=()
if (( ! ${words[2,-1][(I)[^-]*]} || ${words[(I)-[kK]]} )); then
  args1=(
    -A '-*'
    '(-d)-a[make function autoloadable]'
    '(-d)-n[leave existing definitions intact]'
  )
  args2=(
     - d
      '-d[delete]:*:completed command:->ccom'
     - k
      '-k[define widget and key binding]:completion function:->cfun:style:->style:*:key'
     - K
      '-K[define multiple widgets based on function]:*::: :->multi'
  )
else
  args1=(
    '!-a' '!-n'
    '*-N[completion for named command]'
  )
fi

_arguments -C -s -S \
  "$args1[@]" \
  '*-p[completion for command matching pattern]' \
  '*-P[completion for command matching pattern]' \
  ':completion function:->cfun' \
  '*:commands:->com' \
  "$args2[@]" && return 0

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

case $state in
  com)
    pat="${words[(I)-[pP]]}"
    normal="${words[(I)-N]}"
    if (( pat && pat > normal )); then
      _message -e patterns 'pattern'
    else
      _command_names
    fi
  ;;
  ccom)
    _wanted commands expl 'completed command' compadd -k _comps
  ;;
  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
    else
      _wanted functions expl 'completion function' compadd -a list
    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
  ;;
esac