summary refs log tree commit diff
path: root/Completion/Zsh/Command/_which
blob: 07ede39fdb3119325c9ae8bc6ee5b7cbc2dbefd9 (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
#compdef which whence where type

local farg aarg cargs args state line curcontext="$curcontext" ret=1

cargs=( \
  '(-v -c)-w[print command type]' \
  '-p[always do a path search]' \
  '-m[treat the arguments as patterns]' \
  '-s[print symlink free path as well]' \
  '*:commands:->command' )
farg='-f[output contents of functions]'
aarg='-a[print all occurrences in path]'

case ${service} in
  whence)
    _arguments -C -s -A "-*" -S \
      '(-c -w)-v[verbose output]' \
      '(-v -w)-c[csh-like output]' \
      "${cargs[@]}" "$farg" "$aarg" && ret=0
  ;;
  where) _arguments -C -s -A "-*" -S "${cargs[@]}" && ret=0;;
  which) _arguments -C -s -A "-*" -S "${cargs[@]}" "$aarg" && ret=0;;
  type) _arguments -C -s -A "-*" -S "${cargs[@]}" "$aarg" "$farg" && ret=0;;
esac

if [[ "$state" = command ]]; then

  args=( "$@" )

  _alternative -O args \
    'commands:external command:_path_commands' \
    'builtins:builtin command:compadd -k builtins' \
    'functions:shell function:compadd -k functions' \
    'aliases:alias:compadd -k aliases' \
    'reserved-words:reserved word:compadd -k reswords' && ret=0

fi

return ret