]> code.delx.au - pulseaudio/blob - shell-completion/pulseaudio-zsh-completion.zsh
zsh-completion: Fix pacat device completion
[pulseaudio] / shell-completion / pulseaudio-zsh-completion.zsh
1 #compdef pulseaudio pactl pacmd pacat paplay parecord padsp pasuspender
2
3 _devices() {
4 local -a _device_list
5 local cmd _device _device_description _remote_cmd
6
7 if [[ $service == pactl || $service == pacmd ]]; then
8 case $words[$((CURRENT - 1))] in
9 set-sink-input-*) cmd=('sink-inputs');;
10 set-sink-*) cmd=('sinks');;
11 set-source-output-*) cmd=('source-outputs');;
12 set-source-*) cmd=('sources');;
13 suspend-sink) cmd=('sinks');;
14 suspend-source) cmd=('sources');;
15 move-sink-input) cmd=('sink-inputs');;
16 move-source-output) cmd=('source-outputs');;
17 kill-sink-input) cmd=('sink-inputs');;
18 kill-source-output) cmd=('source-outputs');;
19 esac
20
21 case $words[$((CURRENT - 2))] in
22 move-sink-input) cmd=('sinks');;
23 move-source-output) cmd=('sources');;
24 esac
25
26 elif [[ $service == (pacat|paplay|parecord) ]]; then
27 case $words[$((CURRENT))] in
28 --device=*)
29 if [[ $words == *(--playback|-p)[[:space:]]* ||
30 $service == paplay ]]; then
31 cmd=('sinks')
32 elif [[ $words == *(--record|-r)[[:space:]]* ||
33 $service == parecord ]]; then
34 cmd=('sources')
35 else
36 cmd=('sinks' 'sources')
37 fi
38 ;;
39 esac
40
41 case $words[$((CURRENT - 1))] in
42 -d)
43 if [[ $words == *(--playback|-p)[[:space:]]* ||
44 $service == paplay ]]; then
45 cmd=('sinks')
46 elif [[ $words == *(--record|-r)[[:space:]]* ||
47 $service == parecord ]]; then
48 cmd=('sources')
49 else
50 cmd=('sinks' 'sources')
51 fi
52 ;;
53 esac
54
55 fi
56
57 for (( i = 0; i < ${#words[@]}; i++ )) do
58 if [[ ${words[$i]} == -s ]]; then
59 _remote_cmd="-s ${words[$i+1]}"
60 break;
61 fi
62 done
63
64 for target in $cmd; do
65 for device_info in ${(ps:\n\n:)"$(_call_program device_tag "pactl $_remote_cmd list $target 2> /dev/null")"}; do
66 for line in ${(f)device_info}; do
67 if [[ $target == (sink-inputs|source-outputs) ]]; then
68 if [[ $line == (Sink*Input|Source*Output)* ]]; then
69 _device=${line#*\#}
70 elif [[ $line == *application.name* ]]; then
71 _device_description=${line#*= }
72 fi
73
74 else
75 if [[ $words[$((CURRENT - 1))] == *set-sink-formats* ]]; then
76 if [[ $line == Sink* ]]; then
77 _device=${line#*\#}
78 elif [[ $line == *Description:* ]]; then
79 _device_description=${line#*: }
80 fi
81
82 else
83 if [[ $line == *Name:* ]]; then
84 _device=${line#*: }
85 elif [[ $line == *Description:* ]]; then
86 _device_description=${line#*: }
87 fi
88 fi
89 fi
90 done
91 _device_list+=($_device:$_device_description)
92 done
93 done
94
95 _describe 'device list' _device_list
96 }
97
98 _profiles() {
99 local -a _profile_list
100 local _current_card _raw_profiles _profile_name _profile_description _remote_cmd
101
102 _current_card=$words[$((CURRENT - 1))]
103
104 for (( i = 0; i < ${#words[@]}; i++ )) do
105 if [[ ${words[$i]} == -s ]]; then
106 _remote_cmd="-s ${words[$i+1]}"
107 break;
108 fi
109 done
110
111 for card in ${(ps:\n\n:)"$(_call_program profiles_tag "pactl $_remote_cmd list cards 2> /dev/null")"}; do
112 if [[ $card == *$_current_card* ]]; then
113 _raw_profiles=${card##*Profiles:}
114 _raw_profiles=${_raw_profiles%%Active Profile:*}
115 for profile in ${(f)_raw_profiles}; do
116 if [[ $profile != [[:blank:]] ]]; then
117 _profile_name=${profile%%: *}
118 _profile_name=${_profile_name//[[:blank:]]/}
119 _profile_name=${_profile_name//:/\\:}
120 _profile_description=${profile#*: }
121 _profile_list+=($_profile_name:$_profile_description)
122 fi
123 done
124 fi
125 done
126
127 _describe 'profile list' _profile_list
128 }
129
130 _ports() {
131 local -a _port_list
132 local _raw_ports _port_name _port_description _current_device _remote_cmd
133
134 case $words[$((CURRENT - 2))] in
135 set-sink-port) cmd="sinks";;
136 set-source-port) cmd="sources";;
137 set-port-latency-offset) cmd="cards";;
138 esac
139
140 _current_device=$words[$((CURRENT - 1))]
141
142 for (( i = 0; i < ${#words[@]}; i++ )) do
143 if [[ ${words[$i]} == -s ]]; then
144 _remote_cmd="-s ${words[$i+1]}"
145 break;
146 fi
147 done
148
149 for device in ${(ps:\n\n:)"$(_call_program port_tag "pactl $_remote_cmd list $cmd 2> /dev/null")"}; do
150 if [[ $device == *Ports:* && $device == *$_current_device* ]]; then
151 _raw_ports=${device##*Ports:}
152 _raw_ports=${_raw_ports%%Active Port:*}
153 for line in ${(f)_raw_ports}; do
154 if [[ $line != [[:blank:]] &&
155 $line != (*Part?of*|*Properties:*|*device.icon_name*) ]]; then
156 _port_name=${line%%: *}
157 _port_name=${_port_name//[[:blank:]]/}
158 _port_description=${line#*: }
159 _port_list+=($_port_name:$_port_description)
160 fi
161 done
162 fi
163 done
164
165 _describe 'port list' _port_list
166 }
167
168 _cards(){
169 local -a _card_list
170 local _card _cad_name _remote_cmd
171
172 for (( i = 0; i < ${#words[@]}; i++ )) do
173 if [[ ${words[$i]} == -s ]]; then
174 _remote_cmd="-s ${words[$i+1]}"
175 break;
176 fi
177 done
178
179 for card_info in ${(ps:\n\n:)"$(_call_program card_tag "pactl $_remote_cmd list cards 2> /dev/null")"}; do
180 for line in ${(f)card_info}; do
181 if [[ $line == *Name:* ]]; then
182 _card=${line#*: }
183 elif [[ $line == *alsa.long_card_name* ]]; then
184 _card_name=${line#*= \"}
185 _card_name=${_card_name%at*}
186 fi
187 done
188 _card_list+=($_card:$_card_name)
189 done
190
191 _describe 'card list' _card_list
192 }
193
194 _all_modules(){
195 local -a _all_modules_list
196 for module in ${(f)"$(_call_program modules_tag "pulseaudio --dump-modules 2> /dev/null")"}; do
197 _all_modules_list+=${module%% *}
198 done
199 _describe 'module list' _all_modules_list
200 }
201
202 _loaded_modules(){
203 local -a _loaded_modules_list _remote_cmd
204
205 for (( i = 0; i < ${#words[@]}; i++ )) do
206 if [[ ${words[$i]} == -s ]]; then
207 _remote_cmd="-s ${words[$i+1]}"
208 break;
209 fi
210 done
211
212 for module in ${(f)"$(_call_program modules_tag "pactl $_remote_cmd list modules short 2> /dev/null")"}; do
213 _loaded_modules_list+=(${${(ps:\t:)module}[1]}:${${(ps:\t:)module}[2]})
214 done
215 _describe 'module list' _loaded_modules_list
216 }
217
218 _resample_methods() {
219 local -a _resample_method_list
220 for method in ${(f)"$(_call_program modules_tag "pulseaudio --dump-resample-methods 2> /dev/null")"}; do
221 _resample_method_list+=$method
222 done
223 _describe 'resample method list' _resample_method_list
224 }
225
226 _clients() {
227 local -a _client_list
228 local _client _client_description _remote_cmd
229
230 for (( i = 0; i < ${#words[@]}; i++ )) do
231 if [[ ${words[$i]} == -s ]]; then
232 _remote_cmd="-s ${words[$i+1]}"
233 break;
234 fi
235 done
236
237 for client_info in ${(ps:\n\n:)"$(_call_program clients_tag "pactl $_remote_cmd list clients 2> /dev/null")"}; do
238 for line in ${(f)client_info}; do
239 if [[ $line == Client[[:space:]]#* ]]; then
240 _client=${line#*\#}
241 elif [[ $line == *application.name* ]]; then
242 _client_description=${line#*=}
243 fi
244 done
245 _client_list+=($_client:$_client_description)
246 done
247 _describe 'client list' _client_list
248 }
249
250 _pacat_file_formats() {
251 local -a _file_format_list
252 for format in ${(f)"$(_call_program fformats_tag "pacat --list-file-formats")"}; do
253 _file_format_list+=(${${(ps:\t:)format}[1]}:${${(ps:\t:)format}[2]})
254 done
255 _describe 'file format list' _file_format_list
256 }
257
258 _pactl_completion() {
259 _pactl_command(){
260 _pactl_commands=(
261 'help: show help and exit'
262 'stat: dump statistics about the PulseAudio daemon'
263 'info: dump info about the PulseAudio daemon'
264 'list: list modules/sources/streams/cards etc...'
265 'exit: ask the PulseAudio daemon to exit'
266 'upload-sample: upload a sound from a file into the sample cache'
267 'play-sample: play the specified sample from the sample cache'
268 'remove-sample: remove the specified sample from the sample cache'
269 'load-module: load a module'
270 'unload-module: unload a module'
271 'move-sink-input: move a stream to a sink'
272 'move-source-output: move a recording stream to a source'
273 'suspend-sink: suspend or resume a sink'
274 'suspend-source: suspend or resume a source'
275 'set-card-profile: set a card profile:cards:_cards'
276 'set-sink-default: set the default sink'
277 'set-source-default: set the default source'
278 'set-sink-port: set the sink port of a sink'
279 'set-source-port: set the source port of a source'
280 'set-port-latency-offset: set a latency offset on a port'
281 'set-sink-volume: set the volume of a sink'
282 'set-source-volume: set the volume of a source'
283 'set-sink-input-volume: set the volume of a stream'
284 'set-source-output-volume: set the volume of a recording stream'
285 'set-sink-mute: mute a sink'
286 'set-source-mute: mute a source'
287 'set-sink-input-mute: mute a stream'
288 'set-source-output-mute: mute a recording stream'
289 'set-sink-formats: set supported formats of a sink'
290 'subscribe: subscribe to events'
291 )
292 _describe 'pactl commands' _pactl_commands
293 }
294
295 _pactl_list_commands=(
296 'modules: list loaded modules'
297 'sinks: list available sinks'
298 'sources: list available sources'
299 'sink-inputs: list connected sink inputs'
300 'source-outputs: list connected source outputs'
301 'clients: list connected clients'
302 'samples: list samples'
303 'cards: list available cards'
304 )
305
306 _arguments -C \
307 - '(help)' \
308 {-h,--help}'[display this help and exit]' \
309 '--version[show version and exit]' \
310 - '(server)' \
311 {-s,--server}'[name of server to connect to]:host:_hosts' \
312 - '(name)' \
313 {-n,--client-name}'[client name to use]:name' \
314 '::pactl commands:_pactl_command' \
315
316 case $words[$((CURRENT - 1))] in
317 list) _describe 'pactl list commands' _pactl_list_commands;;
318 stat) compadd short;;
319 set-card-profile) _cards;;
320 set-sink-*) _devices;;
321 set-source-*) _devices;;
322 upload-sample) _files;;
323 load-module) _all_modules;;
324 unload-module) _loaded_modules;;
325 suspend-*) _devices;;
326 move-*) _devices;;
327 set-port-latency-offset) _cards;;
328 esac
329
330 case $words[$((CURRENT - 2))] in
331 set-card-profile) _profiles;;
332 set-(sink|source)-port) _ports;;
333 set-port-latency-offset) _ports;;
334 set-*-mute) compadd true false toggle;;
335 suspend-*) compadd true false;;
336 list) compadd short;;
337 move-*) _devices;;
338 '-s' | '-n') _pactl_command;;
339 --server | --client-*) _pactl_command;;
340 esac
341 }
342
343 _pacmd_completion() {
344 _pacmd_command(){
345 _pacmd_commands=(
346 'help: show help and exit'
347 'list-modules: list modules'
348 'list-cards: list cards'
349 'list-sinks: list sinks'
350 'list-sources: list sources'
351 'list-clients: list clients'
352 'list-sink-inputs: list sink-inputs'
353 'list-source-outputs: list source-outputs'
354 'stat: dump statistics about the PulseAudio daemon'
355 'info: dump info about the PulseAudio daemon'
356 'load-module: load a module'
357 'unload-module: unload a module'
358 'describe-module: print info for a module'
359 'set-sink-volume: set the volume of a sink'
360 'set-source-volume: set the volume of a source'
361 'set-sink-mute: mute a sink'
362 'set-source-mute: mute a source'
363 'set-sink-input-volume: set the volume of a stream'
364 'set-source-output-volume: set the volume of a recording stream'
365 'set-sink-input-mute: mute a stream'
366 'set-source-output-mute: mute a recording stream'
367 'set-default-sink: set the default sink'
368 'set-default-source: set the default source'
369 'set-card-profile: set a card profile'
370 'set-sink-port: set the sink port of a sink'
371 'set-source-port: set the source port of a source'
372 'set-port-latency-offset: set a latency offset on a port'
373 'suspend-sink: suspend or resume a sink'
374 'suspend-source: suspend or resume a source'
375 'suspend: suspend all sinks and sources'
376 'move-sink-input: move a stream to a sink'
377 'move-source-output: move a recording stream to a source'
378 'update-sink-proplist: update the properties of a sink'
379 'update-source-proplist: update the properties of a source'
380 'update-sink-input-proplist: update the properties of a sink-input'
381 'update-source-output-proplist: update the properties of a source-output'
382 'list-samples: list samples'
383 'play-sample: play the specified sample from the sample cache' # TODO
384 'remove-sample: remove the specified sample from the sample cache' # TODO
385 'load-sample: upload a sound from a file into the sample cache'
386 'load-sample-lazy: lazily upload a sound file into the sample cache'
387 'load-sample-dir-lazy: lazily upload all sound files in a directory into the sample cache'
388 'kill-client: kill a client'
389 'kill-sink-input: kill a sink input'
390 'kill-source-output: kill a source output'
391 'set-log-target: change the log target'
392 'set-log-level: change the log level'
393 'set-log-meta: show source code location in log messages'
394 'set-log-time: show timestamps in log messages'
395 'set-log-backtrace: show backtrace in log messages'
396 'play-file: play a sound file'
397 'dump: show daemon configuration'
398 'dump-volumes: show the state of all volumes'
399 'shared: show shared properties'
400 'exit: ask the PulseAudio daemon to exit'
401 )
402 _describe 'pacmd commands' _pacmd_commands
403 }
404
405 _arguments -C \
406 - '(help)' \
407 {-h,--help}'[display this help and exit]' \
408 '--version[show version and exit]' \
409 '::pacmd commands:_pacmd_command' \
410
411 case $words[$((CURRENT - 1))] in
412 set-card-profile) _cards;;
413 set-sink-*) _devices;;
414 set-source-*) _devices;;
415 load-module) _all_modules;;
416 describe-module) _all_modules;;
417 unload-module) _loaded_modules;;
418 suspend-*) _devices;;
419 move-*) _devices;;
420 set-port-latency-offset) _cards;;
421 load-sample*) _files;;
422 kill-client) _clients;;
423 kill-(sink|source)-*) _devices;;
424 set-log-target) compadd null auto syslog stderr file:;;
425 set-log-*) compadd true false;;
426 play-file) _files;;
427 esac
428
429 case $words[$((CURRENT - 2))] in
430 set-card-profile) _profiles;;
431 set-(sink|source)-port) _ports;;
432 set-port-latency-offset) _ports;;
433 set-*-mute) compadd true false;;
434 suspend-*) compadd true false;;
435 move-*) _devices;;
436 esac
437 }
438
439 _pasuspender_completion() {
440 _arguments -C \
441 {-h,--help}'[display this help and exit]' \
442 '--version[show version and exit]' \
443 {-s,--server}'[name of server to connect to]:host:_hosts' \
444 }
445
446 _padsp_completion() {
447 _arguments -C \
448 '-h[display this help and exit]' \
449 '-s[name of server to connect to]:host:_hosts' \
450 '-n[client name to use]:name:' \
451 '-m[stream name to use]:name:' \
452 '-M[disable /dev/mixer emulation]' \
453 '-S[disable /dev/sndstat emulation]' \
454 '-D[disable /dev/dsp emulation]' \
455 '-d[enable debug output]' \
456 '--[disable further command line parsing]' \
457 }
458
459 # TODO channel map completion
460 _pacat_completion() {
461 _pacat_sample_formats=('s16le' 's16be' 'u8' 'float32le' 'float32be'
462 'ulaw' 'alaw' 's32le' 's32be' 's24le' 's24-32le' 's24-32be')
463
464 _arguments -C \
465 {-h,--help}'[display this help and exit]' \
466 '--version[show version and exit]' \
467 {-r,--record}'[create a connection for recording]' \
468 {-p,--playback}'[create a connection for playback]' \
469 {-s,--server=}'[name of server to connect to]:host:_hosts' \
470 {-d,--device=}'[name of sink/source to connect to]:device:_devices' \
471 {-n,--client-name=}'[client name to use]:name' \
472 '--stream-name=[how to call this stream]:name' \
473 '--volume=[initial volume to use]:volume' \
474 '--rate=[sample rate to use]:rate:(44100 48000 96000)' \
475 '--format=[sample type to use]:format:((${(q)_pacat_sample_formats}))' \
476 '--channels=[number of channels to use]:number:(1 2)' \
477 '--channel-map=[channel map to use]:map' \
478 '--fix-format[use the sample format of the sink]' \
479 '--fix-rate[use the rate of the sink]' \
480 '--fix-channels[channel map of the sink]' \
481 '--no-remix[do not upmix or downmix channels]' \
482 '--no-remap[map channels by index instead of name]' \
483 '--latency=[request the specified latency]:bytes' \
484 '--process-time=[request the specified process time]:bytes' \
485 '--latency-msec=[request the specified latency in msec]:msec' \
486 '--process-time-msec=[request the specified process time in msec]:msec' \
487 '--property=[set the specified property]:property' \
488 '--raw[record/play raw PCM data]' \
489 '--passthrough[passtrough data]' \
490 '--file-format=[record/play formatted PCM data]:format:_pacat_file_formats' \
491 '--list-file-formats[list available formats]' \
492 '::files:_files' \
493 }
494
495 # TODO log-target file completion
496 _pulseaudio_completion() {
497 _arguments -C \
498 {-h,--help}'[display this help and exit]' \
499 '--version[show version and exit]' \
500 '--dump-conf[show default configuration]' \
501 '--dump-modules[show available modules]' \
502 '--dump-resample-methods[show available resample methods]' \
503 '--cleanup-shm[cleanup shared memory]' \
504 '--start[start the daemon]' \
505 {-k,--kill}'[kill a running daemon]' \
506 '--check[check for a running daemon]' \
507 '--system=[run as systemd-wide daemon]:bool:(true false)' \
508 {-D,--daemonize=}'[daemonize after startup]:bool:(true false)' \
509 '--fail=[quit when startup fails]:bool:(true false)' \
510 '--high-priority=[try to set high nice level]:bool:(true false)' \
511 '--realtime=[try to enable rt scheduling]:bool:(true false)' \
512 '--disallow-module-loading=[disallow module loading]:bool:(true false)' \
513 '--disallow-exit=[disallow user requested exit]' \
514 '--exit-idle-time=[terminate the daemon on passed idle time]:time' \
515 '--scache-idle-time=[unload autoloaded samples on passed idle time]:time' \
516 '--log-level=[set the verbosity level]:level' \
517 '-v[increase the verbosity level]' \
518 '--log-target=[set the log target]:target:(auto syslog stderr file\: new_file\:):file' \
519 '--log-meta=[include code location in log messages]:bool:(true false)' \
520 '--log-time=[include timestamps in log messages]:bool:(true false)' \
521 '--log-backtrace=[include backtrace in log messages]:frames' \
522 {-p,--dl-search-path=}'[set the search path for plugins]:dir:_files' \
523 '--resample-method=[set the resample method]:method:_resample_methods' \
524 '--use-pid-file=[create a PID file]:bool:(true false)' \
525 '--no-cpu-limit=[do not install CPU load limiter]:bool:(true false)' \
526 '--disable-shm=[disable shared memory support]:bool:(true false)' \
527 {-L,--load=}'[load the specified module]:modules:_all_modules' \
528 {-F,--file=}'[run the specified script]:file:_files' \
529 '-C[open a command line on the running tty]' \
530 '-n[do not load the default script file]' \
531 }
532
533 _pulseaudio() {
534 local state line curcontext="$curcontext"
535
536 case $service in
537 pulseaudio) _pulseaudio_completion;;
538 pactl) _pactl_completion;;
539 pacmd) _pacmd_completion;;
540 pacat) _pacat_completion;;
541 paplay)_pacat_completion;;
542 parecord)_pacat_completion;;
543 padsp) _padsp_completion;;
544 pasuspender) _pasuspender_completion;;
545 *) _message "Err";;
546 esac
547 }
548
549 _pulseaudio "$@"
550
551 #vim: set ft=zsh sw=4 ts=4 noet