?
_mblinux()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
prev2="${COMP_WORDS[COMP_CWORD-2]}"
top_opts="--version --help"
top_commands="scan logs update configure daemon register unregister protection exclusions quarantine diag"
# Top-level options, without commands
if [[ ${cur} == "-*" ]] && [[ ${prev} == "mblinux" ]] ; then
COMPREPLY=( $(compgen -W "${top_opts}" -- ${cur}) )
return 0
# Top-level commands
elif [[ ${prev} == "mblinux" ]] ; then
COMPREPLY=( $(compgen -W "${top_commands}" -- ${cur}) )
return 0
# Dig into each subcommand
else
case "$prev" in
scan)
case "$cur" in
-*)
local subopts="--quarantine --help"
COMPREPLY=( $(compgen -fW "${subopts}" -- ${cur}) )
;;
*)
COMPREPLY=( $(compgen -f))
;;
esac
;;
logs)
;;
update)
;;
daemon)
case "$cur" in
-*)
local subopts="--help"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
*)
local subopts="start stop restart status"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
esac
;;
protection)
case "$cur" in
-*)
local subopts="--help"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
*)
local subopts="status"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
esac
;;
exclusions)
case "$cur" in
-*)
local subopts="--help"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
*)
local subopts="list"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
esac
;;
quarantine)
case "$cur" in
-*)
local subopts="--help"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
*)
local subopts="restore delete list"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
esac
;;
help)
;;
esac
# More complex subcommands
case "$prev2" in
quarantine)
case "$prev" in
restore)
local subopts=$( mblinux quarantine list | cut -f1 --delimiter=" " | tail -n+2 | tr '\n' ' ' )
subopts="${subopts} all"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
delete)
local subopts=$( mblinux quarantine list | cut -f1 --delimiter=" " | tail -n+2 | tr '\n' ' ' )
subopts="${subopts} all"
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
esac
;;
exclusions)
case "$prev" in
add)
COMPREPLY=( $(compgen -f))
;;
remove)
local subopts=$( mblinux exclusions list | tr '\n' ' ' )
COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
;;
esac
esac
fi
}
complete -F _mblinux mblinux