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