From 3f86f19f95d36f2e489a25e1996ab2e2d43079ae Mon Sep 17 00:00:00 2001 From: Liam Beguin Date: Mon, 5 Sep 2022 12:39:43 -0400 Subject: 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 --- data/shell-completions/bash/meson | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/data/shell-completions/bash/meson b/data/shell-completions/bash/meson index b4bdb43..9004981 100644 --- a/data/shell-completions/bash/meson +++ b/data/shell-completions/bash/meson @@ -1,26 +1,27 @@ _meson() { command="${COMP_WORDS[1]}" - case "$command" in - setup |\ - configure |\ - dist | \ - install |\ - introspect |\ - init |\ - test |\ - wrap |\ - subprojects |\ - help |\ - rewrite |\ - compile |\ - devenv |\ - env2mfile) + meson_subcommands=( + setup + configure + dist + install + introspect + init + test + wrap + subprojects + help + rewrite + compile + devenv + env2mfile + ) + + if [[ " ${meson_subcommands[*]} " =~ " ${command} " ]]; then _meson-$command "${COMP_WORDS[@]:1}" - ;; - *) + else _meson-setup "${COMP_WORDS[@]}" - ;; - esac + fi } && complete -F _meson meson @@ -197,7 +198,7 @@ _meson-setup() { fi if [ $COMP_CWORD -eq 1 ]; then - COMPREPLY+=($(compgen -W 'setup configure test introspect' -- "$cur")) + COMPREPLY+=($(compgen -W "${meson_subcommands[*]}" -- "$cur")) fi fi } -- cgit v1.1