-
Notifications
You must be signed in to change notification settings - Fork 12
/
zabbix_agentd-completion
91 lines (85 loc) · 2.43 KB
/
zabbix_agentd-completion
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#
# Bash completion for zabbix_agentd
#
shopt -s extglob
_zabbix_agentd()
{
local cur prev opts unique_opts nonunique_opts unique_opts_space nonunique_opts_space opt option
COMPREPLY=()
_get_comp_words_by_ref -n = cur prev
unique_opts="-h|--help|-V|--version"
nonunique_opts="-c|-p|-R|-t|-f|--config|--print|--runtime-control|--test|--foreground"
unique_opts_space=${unique_opts//|/ }
nonunique_opts_space=${nonunique_opts//|/ }
opts=" $unique_opts_space $nonunique_opts_space "
for (( i=1; i<=$[${#COMP_WORDS[@]}-1]; ++i )) ; do
opt=${COMP_WORDS[$i]}
[[ $opt =~ --*[pthvVcRrf].* ]] && {
option=$opt
} || {
continue
}
# if a unique option has been supplied, do not offer any other options
[[ $option == @($unique_opts) ]] && {
return 1
}
# if a non-unique option has been supplied, remove all unique options and already used options
[[ $option == @($nonunique_opts) ]] && opts="${opts/$unique_opts_space/}"
opts=${opts/ $option / }
# remove alternatives
case $option in
-R) opts="${opts/ --runtime-control/}" ;;
--runtime-control) opts="${opts/ -R/}" ;;
-c) opts="${opts/ --config/}" ;;
--config) opts="${opts/ -c/}" ;;
-p) opts="${opts/ --print/}" ;;
--print) opts="${opts/ -o/}" ;;
-t) opts="${opts/ --test/}" ;;
--test) opts="${opts/ -t/}" ;;
esac
# these are exclusive
case "${option}" in
-@(p|-print))
opts="${opts/ -t/}"
opts="${opts/ --test/}"
opts="${opts/ -R/}"
opts="${opts/ --runtime-control/}"
;;
-@(t|-test))
opts="${opts/ -p/}"
opts="${opts/ --print/}"
opts="${opts/ -R/}"
opts="${opts/ --runtime-control/}"
;;
-@(R|-runtime-control))
opts="${opts/ -t/}"
opts="${opts/ --test/}"
opts="${opts/ -p/}"
opts="${opts/ --print/}"
;;
esac
done
case "${prev}" in
-@(c|-config))
compopt -o default
COMPREPLY=()
return 0
;;
-@(R|-runtime-control))
_zabbix-daemons-runtime "$cur" agentd $1
return 0
;;
-@(t|-test))
# get the available item keys (without parameters) from the currently used binary
COMPREPLY=( $(compgen -W "$($1 -p | awk '/\[/{ sub(/\[.*/,"["); if ($1 ~ /^[[:alnum:]._-]+\[?$/) print $1}')" -- ${cur}) )
if [[ $COMPREPLY =~ "[" ]]; then
compopt -o nospace
fi
return 0
;;
*)
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _zabbix_agentd zabbix_agentd