about summary refs log tree commit diff
path: root/Completion/Base/_command_names
blob: 2218aac21ec5cbd6a82d10c8c00b7192c109d745 (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
#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 type=-c

if [[ "$1" = -e ]]; then
  type=-m
  shift
elif [[ "$1" = - ]]; then
  shift
fi

# Complete jobs in implicit fg and bg
if [[ $type = -c && "$PREFIX[1]" = "%" ]]; then
  _description expl job
  compgen "$expl[@]" "$@" -j -P '%'
  [[ nm -ne compstate[nmatches] ]] && return
fi

_description expl command
compgen "$expl[@]" "$@" $type && ret=0

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