wflinfo: bash-completion: fold long opt/args
[mesa-waffle.git] / shell-completion / bash / wflinfo
blob9817f7fc3dfe4ceeb64d0bbbf64323d504568f2d
1 # Formatted using:
2 # shfmt --language-dialect bash --indent 4 --func-next-line
3 _wflinfo()
5     # long/short opt pairs
6     local -A opts=(
7         ['platform']='p'
8         ['api']='a'
9         ['version']='V'
10         ['profile']=''
11         ['verbose']='v'
12         ['forward-compatible']=''
13         ['debug-context']=''
14         ['robust-context']=''
15         ['reset-notification']=''
16         ['format']='f'
17         ['help']='h'
18     )
20     local versions=(1.{0..5} 2.{0..1} 3.{0..3} 4.{0..6})
22     # long opt/arg pairs
23     local -A args=(
24         ['platform']='android cgl gbm glx surfaceless_egl sl wayland wgl x11_egl'
25         ['api']='gl gles1 gles2 gles3'
26         ['version']="${versions[*]}"
27         ['profile']='core compat none'
28         ['format']='original json'
29     )
31     local cur prev
32     _get_comp_words_by_ref cur prev
34     for opt in ${!opts[*]}; do
35         if [[ $prev == -${opts[$opt]} ]] || [[ $prev == --$opt ]]; then
36             local arg="${args[$opt]}"
37             [[ $arg ]] || continue
38             COMPREPLY=($(compgen -W "$arg" -- "$cur"))
39             return
40         fi
41     done
43     if [[ $cur == --* ]]; then
44         COMPREPLY=($(compgen -P '--' -W "${!opts[*]}" -- "${cur:2}"))
45     elif [[ $cur == -* && ${#cur} -gt 1 ]]; then
46         COMPREPLY=($(compgen -P '-' -W "${opts[*]}" -- "${cur:1}"))
47     else
48         COMPREPLY=($(compgen -P '-' -W "${opts[*]}" -- "${cur:1}")
49         $(compgen -P '--' -W "${!opts[*]}" -- "${cur:2}"))
50     fi
51 } &&
52     complete -F _wflinfo wflinfo