42 lines
1.2 KiB
Bash
42 lines
1.2 KiB
Bash
# bash completion for vpn-router-backup -*- shell-script -*-
|
|
|
|
_vpn_router_backup()
|
|
{
|
|
local cur prev words cword split
|
|
_init_completion -s || return
|
|
|
|
# The command is the first word that is not an option; the arguments are the words after it.
|
|
local i command='' args=0 pbs=false
|
|
for ((i = 1; i < cword; i++)); do
|
|
if [[ -z $command ]]; then
|
|
[[ ${words[i]} != -* ]] && command=${words[i]}
|
|
elif [[ ${words[i]} == --pbs ]]; then
|
|
pbs=true
|
|
elif [[ ${words[i]} != -* ]]; then
|
|
((args++))
|
|
fi
|
|
done
|
|
|
|
if [[ -z $command ]]; then
|
|
if [[ $cur == -* ]]; then
|
|
COMPREPLY=($(compgen -W '--help' -- "$cur"))
|
|
else
|
|
COMPREPLY=($(compgen -W 'run list restore' -- "$cur"))
|
|
fi
|
|
return
|
|
fi
|
|
|
|
if [[ $cur == -* ]]; then
|
|
COMPREPLY=($(compgen -W "--help$([[ $command == restore ]] && echo ' --pbs --yes')" -- "$cur"))
|
|
return
|
|
fi
|
|
|
|
# restore takes a local archive, or with --pbs a snapshot name, which vpn-router-backup list shows.
|
|
if [[ $command == restore ]] && ((args == 0)) && ! $pbs; then
|
|
_filedir
|
|
fi
|
|
} &&
|
|
complete -F _vpn_router_backup vpn-router-backup
|
|
|
|
# ex: filetype=sh
|