-
Notifications
You must be signed in to change notification settings - Fork 11
/
zabbix_server-completion
70 lines (63 loc) · 1.84 KB
/
zabbix_server-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
#
# Bash completion for zabbix_server
#
shopt -s extglob
_zabbix_server()
{
local cur prev opts unique_opts nonunique_opts unique_opts_space nonunique_opts_space opt option
local config_supplied config_path pid_file parent_pid
local runtime_simple_options="config_cache_reload housekeeper_execute snmp_cache_reload diaginfo"
local diaginfo_params="alerting historycache lld locks preprocessing valuecache"
COMPREPLY=()
_get_comp_words_by_ref -n = cur prev
unique_opts="-h|--help|-V|--version"
nonunique_opts="-c|-R|-f|--config|--runtime-control|--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]}
[[ $config_supplied ]] && {
config_path=$opt
unset config_supplied
continue
}
[[ $opt =~ --*[hvVcRrf].* ]] && {
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 / }
[[ $option == "-c" ]] && {
config_supplied=yes
}
# remove alternatives
case $option in
-R) opts="${opts/ --runtime-control/}" ;;
--runtime-control) opts="${opts/ -R/}" ;;
-c) opts="${opts/ --config/}" ;;
--config) opts="${opts/ -c/}" ;;
esac
done
case "${prev}" in
-@(c|-config))
compopt -o default
COMPREPLY=()
return 0
;;
-@(R|-runtime-control))
_zabbix-daemons-runtime "$cur" server $1
return 0
;;
*)
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _zabbix_server zabbix_server