-
Notifications
You must be signed in to change notification settings - Fork 0
/
_watch
59 lines (48 loc) · 1.88 KB
/
_watch
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
#compdef watch
setopt localoptions extended_glob
_zsh_watch() {
arguments=(
'(: * -)'{-h,--help}'[display this help and exit]' \
'(: * -)'{-v,--version}'[output version information and exit]' \
'(-b --beep)'{-b,--beep}'[beep if command has a non-zero exit]' \
'(-c --color)'{-c,--color}'[interpret ANSI color and style sequences]' \
'(-d --differences)'{-d-,--differences=-}'[highlight changes between updates]::how to highlight:(permanent)' \
'(-e --errexit)'{-e,--errexit}'[exit if command has a non-zero exit]' \
'(-g --chgexit)'{-g,--chgexit}'[exit when output from command changes]' \
'(-n --interval)'{-n+,--interval=}'[seconds to wait between updates]:secs' \
'(-p --precise)'{-p,--precise}'[attempt run command in precise intervals]' \
'(-r --no-rerun)'{-r,--no-rerun}'[do not rerun program on window resize]' \
'(-t --no-title)'{-t,--no-title}'[turn off header]' \
'(-x --exec)'{-x,--exec}'[pass command to exec instead of "sh -c"]' \
'1: :_command_names -e'
'*:shell arguments:= ->rest'
)
_arguments -A "-*" -S $arguments
case $state in
rest)
# strip watch and its flags
(( strip = $CURRENT - $#line))
(( CURRENT -= strip ))
words[1,strip]=()
# expand aliases
local cmd=( $words[1] )
while (( $+aliases[$cmd[1]] )); do
local newcmd=( ${=aliases[$cmd[1]]} $cmd[2,-1] )
# remove leading envs
while [[ $newcmd[1] = *=* ]]; do
shift newcmd
done
# prevent infinite loop
if [[ $cmd[1] = $newcmd[1] ]]; then
break
fi
cmd=( $newcmd )
done
(( CURRENT += $#cmd - 1 ))
words[1,1]=()
words=( "$cmd[@]" "$words[@]" )
_normal -p $service
;;
esac
}
_zsh_watch