From aafe720dae887c72fd559337fa92c3561fae7711 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 16 Sep 2024 20:35:33 +0100 Subject: [PATCH] wflinfo: bash-completion: fold long opt/args Signed-off-by: Emil Velikov --- shell-completion/bash/wflinfo | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/shell-completion/bash/wflinfo b/shell-completion/bash/wflinfo index b3960f9..9817f7f 100644 --- a/shell-completion/bash/wflinfo +++ b/shell-completion/bash/wflinfo @@ -17,32 +17,28 @@ _wflinfo() ['help']='h' ) + local versions=(1.{0..5} 2.{0..1} 3.{0..3} 4.{0..6}) + + # long opt/arg pairs + local -A args=( + ['platform']='android cgl gbm glx surfaceless_egl sl wayland wgl x11_egl' + ['api']='gl gles1 gles2 gles3' + ['version']="${versions[*]}" + ['profile']='core compat none' + ['format']='original json' + ) + local cur prev _get_comp_words_by_ref cur prev - case $prev in - -p | --platform) - COMPREPLY=($(compgen -W 'android cgl gbm glx surfaceless_egl sl wayland wgl x11_egl' -- "$cur")) - return - ;; - -a | --api) - COMPREPLY=($(compgen -W 'gl gles1 gles2 gles3' -- "$cur")) - return - ;; - -V | --version) - local versions=(1.{0..5} 2.{0..1} 3.{0..3} 4.{0..6}) - COMPREPLY=($(compgen -W "${versions[*]}" -- "$cur")) - return - ;; - --profile) - COMPREPLY=($(compgen -W 'core compat none' -- "$cur")) - return - ;; - -f | --format) - COMPREPLY=($(compgen -W 'original json' -- "$cur")) - return - ;; - esac + for opt in ${!opts[*]}; do + if [[ $prev == -${opts[$opt]} ]] || [[ $prev == --$opt ]]; then + local arg="${args[$opt]}" + [[ $arg ]] || continue + COMPREPLY=($(compgen -W "$arg" -- "$cur")) + return + fi + done if [[ $cur == --* ]]; then COMPREPLY=($(compgen -P '--' -W "${!opts[*]}" -- "${cur:2}")) -- 2.11.4.GIT