1#autoload
2
3# The option `-e' if given as the first argument says that we should
4# complete only external commands and executable files. This and a
5# `-' as the first argument is then removed from the arguments.
6
7local args defs ffilt
8
9zstyle -t ":completion:${curcontext}:commands" rehash && rehash
10
11zstyle -t ":completion:${curcontext}:functions" prefix-needed && \
12 [[ $PREFIX != [_.]* ]] && \
13 ffilt='[(I)[^_.]*]'
14
15defs=(
16  'commands:external command:_path_commands'
17)
18
19[[ -n "$path[(r).]" || $PREFIX = */* ]] &&
20  defs=( "$defs[@]"
21         'executables:executable file or directory:_path_files -/g \*\(-\*\)'
22  )
23
24if [[ "$1" = -e ]]; then
25  shift
26else
27  [[ "$1" = - ]] && shift
28
29  defs=( "$defs[@]"
30    'builtins:builtin command:compadd -Qk builtins'
31    "functions:shell function:compadd -k 'functions$ffilt'"
32    'aliases:alias:compadd -Qk aliases'
33    'suffix-aliases:suffix alias:_suffix_alias_files'
34    'reserved-words:reserved word:compadd -Qk reswords'
35    'jobs:: _jobs -t'
36    'parameters:: _parameters -g "^*readonly*" -qS= -r "\n\t\- =["'
37  )
38fi
39
40args=( "$@" )
41
42local -a cmdpath
43if zstyle -a ":completion:${curcontext}" command-path cmdpath &&
44   [[ $#cmdpath -gt 0 ]]
45then
46  local -a +h path
47  local -A +h commands
48  path=( $cmdpath )
49fi
50_alternative -O args "$defs[@]"
51