about summary refs log tree commit diff
path: root/Completion/Base/_command_names
blob: 5ec984bdc90beddc500b66dae83f3c7c6003fe31 (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
#compdef -command-

# The option `-e' if given as the first argument says that we should
# complete only external commands and executable files. This and a
# `-' as the first argument is then removed from the arguments.

local nm=$compstate[nmatches] ret=1 expl ext

if [[ "$1" = -e ]]; then
  ext=yes
  shift
elif [[ "$1" = - ]]; then
  shift
fi

# Complete jobs in implicit fg and bg
if [[ -z "$ext" && "$PREFIX[1]" = "%" ]]; then
  _jobs
  [[ nm -ne compstate[nmatches] ]] && return
fi

_description expl 'external command'
compadd "$expl[@]" "$@" - "${(k@)commands}" && ret=0

if [[ -z "$ext" ]]; then
  _description expl 'builtin command'
  compadd "$expl[@]" "$@" - "${(k@)builtins}" && ret=0
  _description expl 'shell function'
  compadd "$expl[@]" "$@" - "${(k@)functions}" && ret=0
  _description expl 'alias'
  compadd "$expl[@]" "$@" - "${(k@)raliases}" && ret=0
  _description expl 'reserved word'
  compadd "$expl[@]" "$@" - "${(k@)reswords}" && ret=0
fi

if [[ nm -eq compstate[nmatches] ]]; then
  _description expl 'executable file or directory'
  _path_files "$expl[@]" "$@" -/g "*(*)"
else
  return ret
fi