summary refs log tree commit diff
path: root/Completion/Zsh/Context/_condition
blob: 0285911acf87453302d81f4122d1ba2662f10580 (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
#compdef -condition-

local prev="$words[CURRENT-1]" ret=1

if [[ "$prev" = -o ]]; then
  _tags -C -o options && _options
elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then
  _tags -C "$prev" files && _files
elif [[ "$prev" = -t ]]; then
  _file_descriptors
elif [[ "$prev" = -v ]]; then
  _parameters -r "\= \t\n\[\-"
else
  if [[ "$PREFIX" = -* ]] ||
     ! zstyle -T ":completion:${curcontext}:options" prefix-needed; then

    if [[ "$prev" = (\[\[|\|\||\&\&|\!|\() ]]; then
      _describe -o 'condition code' \
                '( -a:existing\ file
	           -b:block\ special\ file
	           -c:character\ special\ file
	           -d:directory
	           -e:existing\ file
	           -f:regular\ file
	           -g:setgid\ bit
	           -h:symbolic\ link
	           -k:sticky\ bit
	           -n:non-empty\ string
	           -o:option
	           -p:named\ pipe
	           -r:readable\ file
	           -s:non-empty\ file
	           -t:terminal\ file\ descriptor
	           -u:setuid\ bit
		   -v:set\ variable
	           -w:writable\ file
	           -x:executable\ file
	           -z:empty\ string
	           -L:symbolic\ link
	           -O:own\ file
	           -G:group-owned\ file
	           -S:socket
	           -N:unread\ file)' && ret=0
    else
      _describe -o 'condition code' \
	        '( -nt:newer\ than
	           -ot:older\ than
	           -ef:same\ file
	           -eq:numerically\ equal
	           -ne:numerically\ not\ equal
	           -lt:numerically\ less\ than
	           -le:numerically\ less\ than\ or\ equal
	           -gt:numerically\ greater\ than
	           -ge:numerically\ greater\ than\ or\ equal)' && ret=0
    fi
  fi
  _alternative 'files:: _files' 'parameters:: _parameters' && ret=0

  return ret
fi