1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
# lmms(1) completion -*- shell-script -*-
# use shellcheck: "shellcheck -e bash <filename>"
_lmms_array_contains ()
{
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
_lmms_long_param_of()
{
case "$1" in
-a)
echo "float"
;;
-b)
echo "bitrate"
;;
-c)
echo "config"
;;
-f)
echo "format"
;;
-i)
echo "interpolation"
;;
-l)
echo "loop"
;;
-m)
echo "mode"
;;
-o)
echo "output"
;;
-p)
echo "profile"
;;
-s)
echo "samplerate"
;;
-x)
echo "oversampling"
;;
*)
echo ""
;;
esac
}
_lmms_conv_old_action ()
{
case "$1" in
-d|--dump)
echo "dump"
;;
-r|--render)
echo "render"
;;
--rendertracks)
echo "rendertracks"
;;
-u|--upgrade)
echo "upgrade"
;;
*)
echo ""
;;
esac
}
_lmms()
{
local cword=$COMP_CWORD
local cur="${COMP_WORDS[COMP_CWORD]}"
# call routine provided by bash-completion
_init_completion || return
local params filemode filetypes
local i # counter variable
local pars_global pars_noaction pars_render actions shortargs
pars_global=(--allowroot --config --help --version)
pars_noaction=(--geometry --import)
pars_render=(--float --bitrate --format --interpolation)
pars_render+=(--loop --mode --output --profile)
pars_render+=(--samplerate --oversampling)
actions=(dump render rendertracks upgrade)
actions_old=(-d --dump -r --render --rendertracks -u --upgrade)
shortargs+=(-a -b -c -f -h -i -l -m -o -p -s -v -x)
local prev prev2
if [ "$cword" -gt 1 ]
then
prev=${COMP_WORDS[cword-1]}
fi
if [ "$cword" -gt 2 ]
then
prev2=${COMP_WORDS[cword-2]}
fi
# don't show shortargs, but complete them when entered
if [[ $cur =~ ^-[^-]$ ]]
then
if _lmms_array_contains "$cur" "${shortargs[@]}"
then
COMPREPLY=( "$cur" )
fi
return
fi
#
# please keep those in order like def_pars_args above
#
case $prev in
--bitrate|-b)
params="64 96 128 160 192 256 320"
;;
--config|-c)
filetypes='xml'
filemode='existing_files'
;;
--format|-f)
params='wav ogg mp3'
;;
--geometry)
# we can not name all possibilities, but this helps the user
# by showing them how the format is
params='0x0+0+0'
;;
--interpolation|-i)
params='linear sincfastest sincmedium sincbest'
;;
--import)
filetypes='mid|midi|MID|MIDI|rmi|RMI|h2song|H2SONG'
filemode='existing_files'
;;
--mode|-m)
params='s j m'
;;
--output|-o)
# default assumption: could be both
local render=1 rendertracks=1
for i in "${!COMP_WORDS[@]}"
do
if [[ ${COMP_WORDS[i]} =~ ^(render|-r|--render)$ ]]
then
rendertracks=
elif [[ ${COMP_WORDS[i]} =~ ^(rendertracks|--rendertracks)$ ]]
then
render=
fi
done
if [ "$rendertracks" ]
then
filemode='existing_directories'
fi
if [ "$render" ]
then
# filemode files is a superset of "existing directories"
# so it's OK to overwrite the filemode='existing_directories'
# from above
filetypes='wav|ogg|mp3'
filemode='files'
fi
;;
--profile|-p)
filemode='files'
;;
--samplerate|-s)
# these are the ones suggested for zyn
# if you think more are required,
# remove this comment and write a justification
params='44100 48000 96000 192000'
;;
--oversampling|-x)
params='1 2 4 8'
;;
*)
local action_found
# Is an action specified?
if [ "$cword" -gt 1 ]
then
local wrd
for wrd in "${COMP_WORDS[@]}"
do
# action named explicitly?
if _lmms_array_contains "$wrd" "${actions[@]}"
then
action_found=$wrd
break
# deprecated action name?
elif _lmms_array_contains "$wrd" "${actions_old[@]}"
then
action_found="$(_lmms_conv_old_action "$wrd")"
break
# no-action params found?
elif _lmms_array_contains "$wrd" "${pars_noaction[@]}"
then
action_found=none
break
fi
done
fi
if [[ $prev =~ -e|--help|-h|-version|-v ]]
then
# the -e flag (from --import) and help/version
# always mark the end of arguments
return
fi
if [[ "$action_found" =~ dump|none|^$ ]] && [[ $prev =~ \.mmpz? ]]
then
# mmp(z) mark the end of arguments for those actions
return
fi
local savefiletypes='mmpz|mmp'
local params_array
# find parameters/filetypes/dirtypes depending on actions
if ! [ "$action_found" ]
then
params_array=( "${actions[@]}" "${pars_global[@]}" "${pars_noaction[@]}")
filemode="existing_files"
filetypes="$savefiletypes"
elif [ "$action_found" == "none" ]
then
params_array=( "${pars_noaction[@]}" )
filemode="existing_files"
filetypes="$savefiletypes"
elif [ "$action_found" == "dump" ]
then
filemode="existing_files"
filetypes="mmpz"
elif [ "$action_found" == "upgrade" ]
then
if [ "$prev" == "upgrade" ]
then
filemode="existing_files"
filetypes="$savefiletypes"
elif [ "$prev2" == "upgrade" ]
then
filemode="files"
filetypes="$savefiletypes"
fi
elif [[ "$action_found" =~ render(tracks)? ]]
then
if [[ "$prev" =~ render(tracks)? ]]
then
filemode="existing_files"
filetypes="$savefiletypes"
else
params_array=( "${pars_render[@]}" )
fi
fi
# add params_array to params, but also check the history of comp words
local param
for param in "${params_array[@]}"
do
local do_append=1
for i in "${!COMP_WORDS[@]}"
do
if [ "$i" -ne 0 ] && [ "$i" -ne "$cword" ]
then
# disallow double long parameters
if [ "${COMP_WORDS[$i]}" == "$param" ]
then
do_append=
# disallow double short parameters
elif [ "--$(_lmms_long_param_of "${COMP_WORDS[$i]}")" == "$param" ]
then
do_append=
# --help or --version must be the first parameters
elif [ "$cword" -gt 1 ] && [[ $param =~ --help|--version ]]
then
do_append=
fi
fi
done
if [ "$do_append" ]
then
params+="$param "
fi
done
;;
esac
case $filemode in
# use completion routine provided by bash-completion
# to fill $COMPREPLY
existing_files)
_filedir "@($filetypes)"
;;
existing_directories)
_filedir -d
;;
files)
# non existing files complete like directories...
_filedir -d
# ...except for non-completing files with the right file type
if [ ${#COMPREPLY[@]} -eq 0 ]
then
if ! [[ "$cur" =~ /$ ]] && [ "$filetypes" ] && [[ "$cur" =~ \.($filetypes)$ ]]
then
# file ending fits, we seem to be done
COMPREPLY=( "$cur" )
fi
fi
;;
esac
if [ "$params" ]
then
# none of our parameters contain spaces, so deactivate shellcheck's warning
# shellcheck disable=SC2207
COMPREPLY+=( $(compgen -W "${params}" -- "${cur}") )
fi
}
complete -F _lmms lmms
|