]> code.delx.au - pulseaudio/blob - shell-completion/pulseaudio-bash-completion.sh
alsa-mixer: Add surround 2.1 profile
[pulseaudio] / shell-completion / pulseaudio-bash-completion.sh
1 #!/bin/bash
2
3 __cards () {
4 while IFS=$'\t' read idx name _; do
5 printf "%s %s\n" "$idx" "$name"
6 done < <(pactl list cards short 2> /dev/null)
7 }
8
9 __sinks () {
10 while IFS=$'\t' read _ name _ _ _; do
11 printf "%s\n" "$name"
12 done < <(pactl list sinks short 2> /dev/null)
13 }
14
15 __sinks_idx () {
16 while IFS=$'\t' read idx _ _ _ _; do
17 printf "%s\n" "$idx"
18 done < <(pactl list sinks short 2> /dev/null)
19 }
20
21 __sources () {
22 while IFS=$'\t' read _ name _ _ _; do
23 printf "%s\n" "$name"
24 done < <(pactl list sources short 2> /dev/null)
25 }
26
27 __sink_inputs () {
28 while IFS=$'\t' read idx _ _ _ _; do
29 printf "%s\n" "$idx"
30 done < <(pactl list sink-inputs short 2> /dev/null)
31 }
32
33 __source_outputs () {
34 while IFS=$'\t' read idx _ _ _ _; do
35 printf "%s\n" "$idx"
36 done < <(pactl list source-outputs short 2> /dev/null)
37 }
38
39 __ports () {
40 pactl list cards 2> /dev/null | awk -e \
41 '/^\tPorts:/ {
42 flag=1; next
43 }
44
45 /^\t[A-Za-z]/ {
46 flag=0
47 }
48
49 flag {
50 if (/^\t\t[A-Za-z]/)
51 ports = ports substr($0, 3, index($0, ":")-3) " "
52 }
53
54 END {
55 print ports
56 }'
57 }
58
59 __profiles () {
60 pactl list cards 2> /dev/null | awk -e \
61 '/^\tProfiles:/ {
62 flag=1; next
63 }
64
65 /^\t[A-Za-z]/ {
66 flag=0
67 }
68
69 flag {
70 if (/^\t\t[A-Za-z]/)
71 profiles = profiles substr($0, 3, index($0, ": ")-3) " "
72 }
73
74 END {
75 print profiles
76 }'
77 }
78
79 __all_modules () {
80 while read name; do
81 name=${name%% *}
82 printf "%s\n" "$name"
83 done < <(pulseaudio --dump-modules 2> /dev/null)
84 }
85
86 __loaded_modules () {
87 while IFS=$'\t' read idx name _; do
88 printf "%s %s\n" "$idx" "$name"
89 done < <(pactl list modules short 2> /dev/null)
90 }
91
92 __resample_methods () {
93 while read name; do
94 printf "%s\n" "$name"
95 done < <(pulseaudio --dump-resample-methods 2> /dev/null)
96 }
97
98 _pacat_file_formats () {
99 while IFS=$'\t' read name _; do
100 printf "%s\n" "$name"
101 done < <(pacat --list-file-formats 2> /dev/null)
102 }
103
104 in_array() {
105 local i
106 for i in "${@:2}"; do
107 [[ $1 = "$i" ]] && return
108 done
109 }
110
111 _pactl() {
112 local cur prev words cword preprev command
113 local comps
114 local flags='-h --help --version -s --server= --client-name='
115 local list_types='short sinks sources sink-inputs source outputs cards
116 modules samples clients'
117 local commands=(stat info list exit upload-sample play-sample remove-sample
118 load-module unload-module move-sink-input move-source-output
119 suspend-sink suspend-source set-card-profile set-sink-port
120 set-source-port set-sink-volume set-source-volume
121 set-sink-input-volume set-source-output-volume set-sink-mute
122 set-source-mute set-sink-input-mute set-source-output-mute
123 set-sink-formats set-port-latency-offset subscribe help)
124
125 _init_completion -n = || return
126 preprev=${words[$cword-2]}
127
128 for word in "${COMP_WORDS[@]}"; do
129 if in_array "$word" "${commands[@]}"; then
130 command=$word
131 break
132 fi
133 done
134
135 case $preprev in
136 list) COMPREPLY=($(compgen -W 'short' -- "$cur")) ;;
137
138 play-sample)
139 comps=$(__sinks)
140 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
141 ;;
142
143 move-sink-input)
144 comps=$(__sinks)
145 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
146 ;;
147
148 move-source-output)
149 comps=$(__sources)
150 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
151 ;;
152
153 set-card-profile)
154 comps=$(__profiles)
155 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
156 ;;
157
158 set-*-port)
159 comps=$(__ports)
160 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
161 ;;
162
163 set-*-mute) COMPREPLY=($(compgen -W 'true false toggle' -- "$cur")) ;;
164
165 set-sink-formats)
166 ;; #TODO
167
168 set-port-*)
169 comps=$(__ports)
170 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
171 ;;
172 --server)
173 compopt +o nospace
174 _known_hosts_real "$cur"
175 ;;
176 esac
177 [[ $COMPREPLY ]] && return 0
178
179 case $prev in
180 list) COMPREPLY=($(compgen -W '${list_types[*]}' -- "$cur")) ;;
181
182 stat) COMPREPLY=($(compgen -W 'short' -- "$cur")) ;;
183
184 upload-sample) _filedir ;;
185
186 play-sample) ;; # TODO
187
188 remove-sample) ;; # TODO
189
190 load-module)
191 comps=$(__all_modules)
192 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
193 ;;
194
195 unload-module)
196 comps=$(__loaded_modules)
197 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
198 ;;
199
200 set-card*)
201 comps=$(__cards)
202 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
203 ;;
204
205 *sink-input*)
206 comps=$(__sink_inputs)
207 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
208 ;;
209
210 *source-output*)
211 comps=$(__source_outputs)
212 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
213 ;;
214
215 set-sink-formats)
216 comps=$(__sinks_idx)
217 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
218 ;;
219
220 *sink*)
221 comps=$(__sinks)
222 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
223 ;;
224
225 *source*)
226 comps=$(__sources)
227 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
228 ;;
229
230 set-port*)
231 comps=$(__cards)
232 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
233 ;;
234
235 -s)
236 _known_hosts_real "$cur" ;;
237 esac
238 [[ $COMPREPLY ]] && return 0
239
240 case $cur in
241 --server=*)
242 cur=${cur#*=}
243 _known_hosts_real "$cur"
244 ;;
245
246 -*)
247 COMPREPLY=($(compgen -W '${flags[*]}' -- "$cur"))
248 [[ $COMPREPLY == *= ]] && compopt -o nospace
249 ;;
250
251 *)
252 [[ -z $command ]] && COMPREPLY=($(compgen -W '${commands[*]}' -- "$cur"))
253 ;;
254 esac
255 }
256 complete -F _pactl pactl
257
258 _pacmd() {
259 local cur prev words cword preprev command
260 local comps
261 local flags='-h --help --version'
262 local commands=(exit help list-modules list-cards list-sinks list-sources list-clients
263 list-samples list-sink-inputs list-source-outputs stat info
264 load-module unload-module describe-module set-sink-volume
265 set-source-volume set-sink-input-volume set-source-output-volume
266 set-sink-mute set-source-mut set-sink-input-mute
267 set-source-output-mute update-sink-proplist update-source-proplist
268 update-sink-input-proplist update-source-output-proplist
269 set-default-sink set-default-source kill-client kill-sink-input
270 kill-source-output play-sample remove-sample load-sample
271 load-sample-lazy load-sample-dir-lazy play-file dump
272 move-sink-input move-source-output suspend-sink suspend-source
273 suspend set-card-profile set-sink-port set-source-port
274 set-port-latency-offset set-log-target set-log-level set-log-meta
275 set-log-time set-log-backtrace)
276 _init_completion -n = || return
277 preprev=${words[$cword-2]}
278
279 for word in "${COMP_WORDS[@]}"; do
280 if in_array "$word" "${commands[@]}"; then
281 command=$word
282 break
283 fi
284 done
285
286 case $preprev in
287 play-sample|play-file)
288 comps=$(__sinks)
289 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
290 ;;
291
292 load-sample*) _filedir ;;
293
294 move-sink-input)
295 comps=$(__sinks)
296 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
297 ;;
298
299 move-source-output)
300 comps=$(__sources)
301 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
302 ;;
303
304 set-card-profile)
305 comps=$(__profiles)
306 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
307 ;;
308
309 set-*port*)
310 comps=$(__ports)
311 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
312 ;;
313
314 set-*-mute) COMPREPLY=($(compgen -W 'true false' -- "$cur"));;
315
316 set-sink-formats)
317 ;; #TODO
318 esac
319
320 case $prev in
321 list-*) ;;
322 describe-module|load-module)
323 comps=$(__all_modules)
324 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
325 ;;
326
327 unload-module)
328 comps=$(__loaded_modules)
329 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
330 ;;
331
332 load-sample-dir-lazy) _filedir -d ;;
333 play-file) _filedir ;;
334
335 *sink-input*)
336 comps=$(__sink_inputs)
337 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
338 ;;
339
340 *source-output*)
341 comps=$(__source_outputs)
342 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
343 ;;
344
345 *sink*)
346 comps=$(__sinks)
347 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
348 ;;
349
350 *source*)
351 comps=$(__sources)
352 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
353 ;;
354
355 set-card*)
356 comps=$(__cards)
357 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
358 ;;
359
360 set-port-*)
361 comps=$(__cards)
362 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
363 ;;
364
365 set-log-target)
366 COMPREPLY=($(compgen -W 'auto syslog stderr file: newfile:' -- "$cur"))
367 ;;
368
369 set-log-level)
370 COMPREPLY=($(compgen -W '{0..4}' -- "$cur"))
371 ;;
372
373 set-log-meta|set-log-time|suspend)
374 COMPREPLY=($(compgen -W 'true false' -- "$cur"))
375 ;;
376 esac
377
378 case $cur in
379 -*) COMPREPLY=($(compgen -W '${flags[*]}' -- "$cur")) ;;
380 suspend)
381 COMPREPLY=($(compgen -W 'suspend suspend-sink suspend-source' -- "$cur"))
382 ;;
383
384 load-sample)
385 COMPREPLY=($(compgen -W 'load-sample load-sample-lazy load-sample-dir-lazy' -- "$cur"))
386 ;;
387
388 *)
389 [[ -z $command ]] && COMPREPLY=($(compgen -W '${commands[*]}' -- "$cur"))
390 ;;
391 esac
392 }
393 complete -F _pacmd pacmd
394
395 _pasuspender () {
396 local cur prev
397 local flags='-h --help --version -s --server='
398
399 _init_completion -n = || return
400
401 case $cur in
402 --server=*)
403 cur=${cur#*=}
404 _known_hosts_real "$cur"
405 ;;
406
407 -*)
408 COMPREPLY=($(compgen -W '${flags[*]}' -- "$cur"))
409 [[ $COMPREPLY == *= ]] && compopt -o nospace
410 ;;
411 esac
412
413 case $prev in
414 -s) _known_hosts_real "$cur" ;;
415 esac
416 }
417 complete -F _pasuspender pasuspender
418
419 _padsp () {
420 local cur prev
421 local flags='-h -s -n -m -M -S -D -d'
422
423 _get_comp_words_by_ref cur prev
424
425 case $cur in
426 -*) COMPREPLY=($(compgen -W '${flags[*]}' -- "$cur")) ;;
427 esac
428
429 case $prev in
430 -s) _known_hosts_real "$cur" ;;
431 esac
432 }
433 complete -F _padsp padsp
434
435 _pacat () {
436 local cur prev comps
437 local flags='-h --help --version -r --record -p --playback -v --verbose -s
438 --server= -d --device= -n --client-name= --stream-name= --volume=
439 --rate= --format= --channels= --channel-map= --fix-format --fix-rate
440 --fix-channels --no-remix --no-remap --latency= --process-time=
441 --latency-msec= --process-time-msec= --property= --raw --passthrough
442 --file-format= --list-file-formats --monitor-stream='
443
444 _init_completion -n = || return
445
446 case $cur in
447 --server=*)
448 cur=${cur#*=}
449 _known_hosts_real "$cur"
450 ;;
451
452 --device=*)
453 cur=${cur#*=}
454 comps=$(__sinks)
455 comps+=" "$(__sources)
456 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
457 ;;
458
459 --monitor-stream=*)
460 cur=${cur#*=}
461 comps=$(__sink_inputs)
462 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
463 ;;
464
465 --rate=*)
466 cur=${cur#*=}
467 COMPREPLY=($(compgen -W '32000 44100 48000 9600 192000' -- "$cur"))
468 ;;
469
470 --file-format=*)
471 cur=${cur#*=}
472 comps=$(_pacat_file_formats)
473 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
474 ;;
475
476 --*=*)
477 ;;
478
479 -*)
480 COMPREPLY=($(compgen -W '${flags[*]}' -- "$cur"))
481 [[ $COMPREPLY == *= ]] && compopt -o nospace
482 ;;
483 *) _filedir ;;
484 esac
485
486 case $prev in
487 -s) _known_hosts_real "$cur" ;;
488 -d)
489 comps=$(__sinks)
490 comps+=" "$(__sources)
491 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
492 ;;
493 esac
494 }
495 complete -F _pacat pacat paplay parec parecord
496
497 _pulseaudio()
498 {
499 local cur prev words cword
500 local flags='-h --help --version --dump-conf --dump-resample-methods --cleanup-shm
501 --start -k --kill --check --system= -D --daemonize= --fail= --high-priority=
502 --realtime= --disallow-module-loading= --disallow-exit= --exit-idle-time=
503 --scache-idle-time= --log-level= -v --log-target= --log-meta= --log-time=
504 --log-backtrace= -p --dl-search-path= --resample-method= --use-pit-file=
505 --no-cpu-limit= --disable-shm= -L --load= -F --file= -C -n'
506 _init_completion -n = || return
507
508 case $cur in
509 --system=*|--daemonize=*|--fail=*|--high-priority=*|--realtime=*| \
510 --disallow-*=*|--log-meta=*|--log-time=*|--use-pid-file=*| \
511 --no-cpu-limit=*|--disable-shm=*)
512 cur=${cur#*=}
513 COMPREPLY=($(compgen -W 'true false' -- "$cur"))
514 ;;
515
516 --log-target=*)
517 cur=${cur#*=}
518 COMPREPLY=($(compgen -W 'auto syslog stderr file: newfile:' -- "$cur"))
519 ;;
520
521 --log-level=*)
522 cur=${cur#*=}
523 COMPREPLY=($(compgen -W '{0..4}' -- "$cur"))
524 ;;
525
526 --dl-search-path=*)
527 cur=${cur#*=}
528 _filedir -d
529 ;;
530
531 --file=*)
532 cur=${cur#*=}
533 _filedir
534 ;;
535
536 --resample-method=*)
537 cur=${cur#*=}
538 comps=$(__resample_methods)
539 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
540 ;;
541
542 --load=*)
543 cur=${cur#*=}
544 comps=$(__all_modules)
545 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
546 ;;
547
548 --*=*)
549 ;;
550
551 -*)
552 COMPREPLY=($(compgen -W '${flags[*]}' -- "$cur"))
553 [[ $COMPREPLY == *= ]] && compopt -o nospace
554 ;;
555 esac
556
557 case $prev in
558 -D) COMPREPLY=($(compgen -W 'true false' -- "$cur")) ;;
559 -p) _filedir -d ;;
560 -F) _filedir ;;
561 -L)
562 cur=${cur#*=}
563 comps=$(__all_modules)
564 COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
565 ;;
566 esac
567 }
568 complete -F _pulseaudio pulseaudio
569
570 #vim: set ft=zsh sw=4 ts=4 noet