completions: bash: define sub-commands as an array

Define subcommands as an array so that they can be reused for the
top-level sub-command completion.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
This commit is contained in:
Liam Beguin 2022-09-05 12:39:43 -04:00 committed by Xavier Claessens
parent 24e97e1945
commit 3f86f19f95
1 changed files with 21 additions and 20 deletions

View File

@ -1,26 +1,27 @@
_meson() { _meson() {
command="${COMP_WORDS[1]}" command="${COMP_WORDS[1]}"
case "$command" in meson_subcommands=(
setup |\ setup
configure |\ configure
dist | \ dist
install |\ install
introspect |\ introspect
init |\ init
test |\ test
wrap |\ wrap
subprojects |\ subprojects
help |\ help
rewrite |\ rewrite
compile |\ compile
devenv |\ devenv
env2mfile) env2mfile
)
if [[ " ${meson_subcommands[*]} " =~ " ${command} " ]]; then
_meson-$command "${COMP_WORDS[@]:1}" _meson-$command "${COMP_WORDS[@]:1}"
;; else
*)
_meson-setup "${COMP_WORDS[@]}" _meson-setup "${COMP_WORDS[@]}"
;; fi
esac
} && } &&
complete -F _meson meson complete -F _meson meson
@ -197,7 +198,7 @@ _meson-setup() {
fi fi
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY+=($(compgen -W 'setup configure test introspect' -- "$cur")) COMPREPLY+=($(compgen -W "${meson_subcommands[*]}" -- "$cur"))
fi fi
fi fi
} }