contrib: bash: completion.bash: complete options without =

Currently, option arguments are only completed after =. For example:

	$ btrbk --loglevel=<TAB>
	debug  error  info   trace  warn
	$ btrbk --loglevel <TAB>
	archive   diff      extents   ls        prune     run
	stats     clean     dryrun    list      origin    resume
	snapshot  usage

This commit makes it so that both option styles are recognized:

	$ btrbk --loglevel=<TAB>
	debug  error  info   trace  warn
	$ btrbk --loglevel <TAB>
	debug  error  info   trace  warn

This was the intention all along, but it was implemented incorrectly.
pull/485/head
Asbjørn Apeland 2022-02-10 23:53:24 +01:00 committed by Axel Burri
parent a8a5051f79
commit b618c2dd90
1 changed files with 13 additions and 1 deletions

View File

@ -4,7 +4,7 @@ _btrbk_init_cmds()
# #
# for example, for this command: # for example, for this command:
# #
# btrbk -v list config --long # btrbk -v --override warn_unknown_targets=yes list config --long
# #
# then $cmds is: # then $cmds is:
# #
@ -14,6 +14,11 @@ _btrbk_init_cmds()
local i local i
for ((i = 1; i < cword; i++)); do for ((i = 1; i < cword; i++)); do
case "${words[i-1]}" in
'-c' | '--config' | '--exclude' | '-l' | '--loglevel' | '--format' | '--lockfile' | '--override')
continue
;;
esac
[[ ${words[i]} != -* ]] && cmds+=(${words[i]}) [[ ${words[i]} != -* ]] && cmds+=(${words[i]})
done done
@ -29,21 +34,28 @@ _btrbk()
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
if [[ $cur == -* ]]; then if [[ $cur == -* ]]; then