blob: 21677841efb391da0bbaaf887ec7759754b89e12 (
plain)
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
61
62
|
#compdef mach
_mach_complete()
{
local com coms comsubs cur optkey opts state sub subs
cur=${words[${#words[@]}]}
typeset -A comsubs
comsubs=( %(commands_subcommands)s )
# lookup for command and subcommand
for word in ${words[@]:1}; do
if [[ $word == -* ]]; then
continue
fi
if [[ -z $com ]]; then
com=$word
elif [[ ${comsubs[$com]} == *" $word "* ]]; then
sub=$word
break
fi
done
# check for a subcommand
if [[ $cur == $com ]]; then
state="command"
coms=(%(commands)s)
elif [[ ${cur} == -* ]]; then
state="option"
if [[ -z $com ]]; then
# no command, use global options
opts=(%(globalopts)s)
fi
fi
case $state in
(command)
_describe 'command' coms
;;
(option)
if [[ -n $sub ]]; then
optkey="$com $sub"
else
optkey="$com"
fi
case $optkey in
%(case_options)s
esac
_describe 'option' opts
;;
*)
if [[ -z $sub ]]; then
# if we're completing a command with subcommands, add them here
case "$com" in
%(case_subcommands)s
esac
_describe 'subcommand' subs
fi
# also fallback to file completion
_arguments '*:file:_files'
esac
}
_mach_complete "$@"
compdef _mach_complete mach
|