zynaddsubfx.in (8146B)
1 # zynaddsubfx(1) completion -*- shell-script -*- 2 3 _zynaddsubfx_array_contains () 4 { 5 local e match="$1" 6 shift 7 for e; do [[ "$e" == "$match" ]] && return 0; done 8 return 1 9 } 10 11 _zynaddsubfx_long_param_of() 12 { 13 case "$1" in 14 -l) 15 echo "load" 16 ;; 17 -L) 18 echo "load-instrument" 19 ;; 20 -M) 21 echo "midi-learn" 22 ;; 23 -r) 24 echo "sample-rate" 25 ;; 26 -b) 27 echo "buffer-size" 28 ;; 29 -o) 30 echo "oscil-size" 31 ;; 32 -S) 33 echo "swap" 34 ;; 35 -U) 36 echo "no-gui" 37 ;; 38 -N) 39 echo "named" 40 ;; 41 -a) 42 echo "auto-connect" 43 ;; 44 -A) 45 echo "auto-save" 46 ;; 47 -p) 48 echo "pid-in-client" 49 ;; 50 -P) 51 echo "preferred-port" 52 ;; 53 -O) 54 echo "output" 55 ;; 56 -I) 57 echo "input" 58 ;; 59 -e) 60 echo "exec-after-init" 61 ;; 62 -d) 63 echo "dump-oscdoc" 64 ;; 65 -D) 66 echo "dump-json-schema" 67 ;; 68 *) 69 echo "" 70 ;; 71 esac 72 } 73 74 _zynaddsubfx() 75 { 76 local cword=$COMP_CWORD 77 local cur="${COMP_WORDS[COMP_CWORD]}" 78 local params filetypes pars shortargs 79 80 # call routine provided by bash-completion 81 _init_completion || return 82 83 # pars without args 84 pars=(--help --version --auto-connect --no-gui --swap) 85 pars+=(--pid-in-client-name) 86 # pars with args 87 pars+=(--load --load-instrument --midi-learn) 88 pars+=(--sample-rate --buffer-size --oscil-size) 89 pars+=(--named --auto-save) 90 pars+=(--preferred-port --output --input) 91 pars+=(--exec-after-init --dump-oscdoc --dump-json-schema) 92 93 shortargs=(-h -v -l -L -M -r -b -o -S -U -N -a -A -p -P -O -I -e -d -D) 94 95 local prev= 96 if [ "$cword" -gt 1 ] 97 then 98 prev=${COMP_WORDS[cword-1]} 99 fi 100 101 # don't show shortargs, but complete them when entered 102 if [[ $cur =~ ^-[^-]$ ]] 103 then 104 if _zynaddsubfx_array_contains "$cur" "${shortargs[@]}" 105 then 106 COMPREPLY=( "$cur" ) 107 fi 108 return 109 fi 110 111 112 local filemode 113 114 # 115 # please keep those in order like def_pars_args above 116 # 117 case $prev in 118 --load|-l) 119 filetypes=xmz 120 filemode=existing_files 121 ;; 122 --load-instrument|-L) 123 filetypes=xiz 124 filemode=existing_files 125 ;; 126 --midi-learn|-M) 127 filetypes=xlz 128 filemode=existing_files 129 ;; 130 --sample-rate|-r) 131 params="8000 16000 44100 48000 96000 192000" 132 ;; 133 --buffer-size|-b) 134 # less than 32 sounds insane, more than 4096 observed buggy 135 params="32 64 128 256 512 1024 2048 4096" 136 ;; 137 --oscil-size|-o) 138 params="128 256 512 1024 2048 4096" 139 ;; 140 --named|-N) 141 ;; 142 --auto-save|-A) 143 params="30 60 120 180 300 450 600 900 1200 1800 2400 3600 " 144 params+="5400 7200 10800 14400 21600 43200 86400" 145 ;; 146 --preferred-port|-P) 147 params= 148 ;; 149 --input|--output|-I|-O) 150 local jack_enable_cmake=@JackEnable@ 151 local pa_enable_cmake=@PaEnable@ 152 local alsa_enable_cmake=@AlsaEnable@ 153 local oss_enable_cmake=@OssEnable@ 154 155 local jack_enable pa_enable alsa_enable oss_enable 156 [[ $jack_enable_cmake =~ FALSE|0|OFF|^$ ]] || jack_enable=1 157 [[ $pa_enable_cmake =~ FALSE|0|OFF|^$ ]] || pa_enable=1 158 [[ $alsa_enable_cmake =~ FALSE|0|OFF|^$ ]] || alsa_enable=1 159 [[ $oss_enable_cmake =~ FALSE|0|OFF|^$ ]] || oss_enable=1 160 161 params="null" 162 [ "$jack_enable" ] && params+=" jack" 163 [ "$pa_enable" ] && params+=" pa" 164 [ "$alsa_enable" ] && params+=" alsa" 165 [ "$oss_enable" ] && params+=" oss" 166 if [[ $prev =~ --output|-O ]] 167 then 168 [ "$jack_enable" ] && params+=" jack-multi" 169 [ "$oss_enable" ] && params+=" oss-multi" 170 fi 171 172 if [[ $prev =~ --output|-O ]] 173 then 174 for i in "${COMPREPLY[@]}" 175 do 176 if [ "$i" == '-a' ] || [ "$i" == '--autoconnect' ] 177 then 178 params="jack jack-multi" 179 break; 180 fi 181 done 182 fi 183 ;; 184 --exec-after-init|-e) 185 filemode=executables 186 ;; 187 --dump-oscdoc|-d) 188 filemode=files 189 filetypes=xml 190 ;; 191 --dump-json-schema|-D) 192 filemode=files 193 filetypes=json 194 ;; 195 *) 196 if [[ $prev =~ --help|-h|-version|-v ]] 197 then 198 # the -e flag (from --import) and help/version 199 # always mark the end of arguments 200 return 201 fi 202 203 # add pars to params, but also check the history of comp words 204 local param 205 for param in "${pars[@]}" 206 do 207 local do_append=1 208 for i in "${!COMP_WORDS[@]}" 209 do 210 if [ "$i" -ne 0 ] && [ "$i" -ne "$cword" ] 211 then 212 # disallow double long parameters 213 if [ "${COMP_WORDS[$i]}" == "$param" ] 214 then 215 do_append= 216 # disallow double short parameters 217 elif [ "${COMP_WORDS[$i]:0:1}" == '-' ] && ! [ "${COMP_WORDS[$i]:1:2}" == '-' ] && 218 [ "--$(_zynaddsubfx_long_param_of "${COMP_WORDS[$i]}")" == "$param" ] 219 then 220 do_append= 221 # --help or --version must be the first parameters 222 elif [ "$cword" -gt 1 ] && [[ $param =~ --help|--version ]] 223 then 224 do_append= 225 fi 226 fi 227 done 228 if [ "$do_append" ] 229 then 230 params+="$param " 231 fi 232 done 233 234 ;; 235 esac 236 237 238 case $filemode in 239 240 # use completion routine provided by bash-completion 241 # to fill $COMPREPLY 242 243 existing_files) 244 _filedir "@($filetypes)" 245 ;; 246 247 existing_directories) 248 _filedir -d 249 ;; 250 251 executables) 252 253 _filedir 254 local tmp=("${COMPREPLY[@]}") 255 COMPREPLY=( ) 256 for i in "${!tmp[@]}" 257 do 258 if [ -f "${tmp[i]}" ] && ! [ -x "${tmp[i]}" ] 259 then 260 # if it's a file that can't be executed, omit from completion 261 true 262 else 263 COMPREPLY+=( "${tmp[i]}" ) 264 fi 265 done 266 ;; 267 268 files) 269 270 # non existing files complete like directories... 271 _filedir -d 272 273 # ...except for non-completing files with the right file type 274 if [ ${#COMPREPLY[@]} -eq 0 ] 275 then 276 if ! [[ "$cur" =~ /$ ]] && [ "$filetypes" ] && [[ "$cur" =~ \.($filetypes)$ ]] 277 then 278 # file ending fits, we seem to be done 279 COMPREPLY=( "$cur" ) 280 fi 281 fi 282 ;; 283 284 esac 285 286 if [ "$params" ] 287 then 288 # none of our parameters contain spaces, so deactivate shellcheck's warning 289 # shellcheck disable=SC2207 290 COMPREPLY+=( $(compgen -W "${params}" -- "${cur}") ) 291 fi 292 293 } 294 295 296 complete -F _zynaddsubfx zynaddsubfx