mirror of https://github.com/digint/btrbk
contrib: bash: completion.bash: complete options everywhere
parent
e4f27632a0
commit
ce660a4989
|
@ -4,7 +4,7 @@ _btrbk_init_cmds()
|
||||||
#
|
#
|
||||||
# for example, for this command:
|
# for example, for this command:
|
||||||
#
|
#
|
||||||
# btrbk -v list config
|
# btrbk -v list config --long
|
||||||
#
|
#
|
||||||
# then $cmds is:
|
# then $cmds is:
|
||||||
#
|
#
|
||||||
|
@ -16,94 +16,74 @@ _btrbk_init_cmds()
|
||||||
for ((i = 1; i < cword; i++)); do
|
for ((i = 1; i < cword; i++)); do
|
||||||
[[ ${words[i]} != -* ]] && cmds+=(${words[i]})
|
[[ ${words[i]} != -* ]] && cmds+=(${words[i]})
|
||||||
done
|
done
|
||||||
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_btrbk()
|
_btrbk()
|
||||||
{
|
{
|
||||||
local cur prev words cword split
|
local cur prev words cword split cmds
|
||||||
_init_completion -s || return
|
_init_completion -s || return
|
||||||
|
_btrbk_init_cmds || return
|
||||||
|
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
'-c' | '--config')
|
'-c' | '--config')
|
||||||
_filedir
|
_filedir
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
'--exclude')
|
'--exclude')
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
'-l' | '--loglevel')
|
'-l' | '--loglevel')
|
||||||
COMPREPLY=($(compgen -W 'error warn info debug trace' -- "$cur"))
|
COMPREPLY=($(compgen -W 'error warn info debug trace' -- "$cur"))
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
'--format')
|
'--format')
|
||||||
COMPREPLY=($(compgen -W 'table long raw' -- "$cur"))
|
COMPREPLY=($(compgen -W 'table long raw' -- "$cur"))
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
'--lockfile')
|
'--lockfile')
|
||||||
_filedir
|
_filedir
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
'--override')
|
'--override')
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
$split && return
|
$split && return
|
||||||
|
|
||||||
local cmds
|
if [[ $cur == -* ]]; then
|
||||||
_btrbk_init_cmds
|
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
||||||
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||||
|
else
|
||||||
|
if [[ ! -v 'cmds[0]' ]]; then
|
||||||
|
COMPREPLY=($(compgen -W 'run dryrun snapshot resume prune archive clean stats list usage origin diff ls' -- "$cur"))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
case "${cmds[0]}" in
|
case "${cmds[0]}" in
|
||||||
'archive')
|
'archive')
|
||||||
# <source>
|
# <source>
|
||||||
if [[ ! -v 'cmds[1]' ]]; then
|
if [[ ! -v 'cmds[1]' ]]; then
|
||||||
_filedir -d
|
_filedir -d
|
||||||
return
|
|
||||||
fi
|
|
||||||
# <target>
|
# <target>
|
||||||
if [[ ! -v 'cmds[2]' ]]; then
|
elif [[ ! -v 'cmds[2]' ]]; then
|
||||||
_filedir -d
|
_filedir -d
|
||||||
return
|
|
||||||
fi
|
|
||||||
# [--raw]
|
# [--raw]
|
||||||
if [[ $cur == -* ]]; then
|
elif [[ $cur == -* ]]; then
|
||||||
COMPREPLY=($(compgen -W '--raw' -- "$cur"))
|
COMPREPLY+=($(compgen -W '--raw' -- "$cur"))
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
'list')
|
'list')
|
||||||
if [[ ! -v 'cmds[1]' ]]; then
|
if [[ ! -v 'cmds[1]' ]]; then
|
||||||
COMPREPLY=($(compgen -W 'backups snapshots latest config source volume target' -- "$cur"))
|
COMPREPLY=($(compgen -W 'backups snapshots latest config source volume target' -- "$cur"))
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
'origin')
|
'origin')
|
||||||
# <subvolume>
|
# <subvolume>
|
||||||
if [[ ! -v 'cmds[1]' ]]; then
|
if [[ ! -v 'cmds[1]' ]]; then
|
||||||
_filedir -d
|
_filedir -d
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
'ls')
|
'ls')
|
||||||
# <path>|<url>...
|
# <path>|<url>...
|
||||||
_filedir -d
|
_filedir -d
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ $cur == -* ]]; then
|
|
||||||
# only complete options before commands
|
|
||||||
if [[ ! -v 'cmds[0]' ]]; then
|
|
||||||
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
|
||||||
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ ! -v 'cmds[0]' ]]; then
|
|
||||||
COMPREPLY=($(compgen -W 'run dryrun snapshot resume prune archive clean stats list usage origin diff ls' -- "$cur"))
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
} && complete -F _btrbk btrbk
|
} && complete -F _btrbk btrbk
|
||||||
|
|
||||||
_lsbtr()
|
_lsbtr()
|
||||||
|
@ -114,23 +94,18 @@ _lsbtr()
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
'-c' | '--config')
|
'-c' | '--config')
|
||||||
_filedir
|
_filedir
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
'--override')
|
'--override')
|
||||||
return
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
$split && return
|
$split && return
|
||||||
|
|
||||||
if [[ $cur == -* ]]; then
|
if [[ $cur == -* ]]; then
|
||||||
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
||||||
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||||
return
|
|
||||||
else
|
else
|
||||||
# <path>|<url>...
|
# <path>|<url>...
|
||||||
_filedir -d
|
_filedir -d
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
} && complete -F _lsbtr lsbtr
|
} && complete -F _lsbtr lsbtr
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue