]> code.delx.au - pulseaudio/blob - shell-completion/pulseaudio-zsh-completion.zsh
zsh-completion: Add support for remote servers.
[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-port: set the sink port of a sink'
261 'set-source-port: set the source port of a source'
262 'set-port-latency-offset: set a latency offset on a port'
263 'set-sink-volume: set the volume of a sink'
264 'set-source-volume: set the volume of a source'
265 'set-sink-input-volume: set the volume of a stream'
266 'set-source-output-volume: set the volume of a recording stream'
267 'set-sink-mute: mute a sink'
268 'set-source-mute: mute a source'
269 'set-sink-input-mute: mute a stream'
270 'set-source-output-mute: mute a recording stream'
271 'set-sink-formats: set supported formats of a sink'
272 'subscribe: subscribe to events'
273 )
274 _describe 'pactl commands' _pactl_commands
275 }
276
277 _pactl_list_commands=(
278 'modules: list loaded modules'
279 'sinks: list available sinks'
280 'sources: list available sources'
281 'sink-inputs: list connected sink inputs'
282 'source-outputs: list connected source outputs'
283 'clients: list connected clients'
284 'samples: list samples'
285 'cards: list available cards'
286 )
287
288 _arguments -C \
289 - '(help)' \
290 {-h,--help}'[display this help and exit]' \
291 '--version[show version and exit]' \
292 - '(server)' \
293 {-s,--server}'[name of server to connect to]:host:_hosts' \
294 - '(name)' \
295 {-n,--client-name}'[client name to use]:name' \
296 '::pactl commands:_pactl_command' \
297
298 case $words[$((CURRENT - 1))] in
299 list) _describe 'pactl list commands' _pactl_list_commands;;
300 stat) compadd short;;
301 set-card-profile) _cards;;
302 set-sink-*) _devices;;
303 set-source-*) _devices;;
304 upload-sample) _files;;
305 load-module) _all_modules;;
306 unload-module) _loaded_modules;;
307 suspend-*) _devices;;
308 move-*) _devices;;
309 set-port-latency-offset) _cards;;
310 esac
311
312 case $words[$((CURRENT - 2))] in
313 set-card-profile) _profiles;;
314 set-(sink|source)-port) _ports;;
315 set-port-latency-offset) _ports;;
316 set-*-mute) compadd true false;;
317 suspend-*) compadd true false;;
318 list) compadd short;;
319 move-*) _devices;;
320 '-s' | '-n') _pactl_command;;
321 --server | --client-*) _pactl_command;;
322 esac
323 }
324
325 _pacmd_completion() {
326 _pacmd_command(){
327 _pacmd_commands=(
328 'help: show help and exit'
329 'list-modules: list modules'
330 'list-sinks: list sinks'
331 'list-sources: list sources'
332 'list-clients: list clients'
333 'list-sink-inputs: list sink-inputs'
334 'list-source-outputs: list source-outputs'
335 'stat: dump statistics about the PulseAudio daemon'
336 'info: dump info about the PulseAudio daemon'
337 'load-module: load a module'
338 'unload-module: unload a module'
339 'describe-module: print info for a module'
340 'set-sink-volume: set the volume of a sink'
341 'set-source-volume: set the volume of a source'
342 'set-sink-mute: mute a sink'
343 'set-source-mute: mute a source'
344 'set-sink-input-volume: set the volume of a stream'
345 'set-source-output-volume: set the volume of a recording stream'
346 'set-sink-input-mute: mute a stream'
347 'set-source-output-mute: mute a recording stream'
348 'set-default-sink: set the default sink'
349 'set-default-source: set the default source'
350 'set-card-profile: set a card profile'
351 'set-sink-port: set the sink port of a sink'
352 'set-source-port: set the source port of a source'
353 'set-port-latency-offset: set a latency offset on a port'
354 'suspend-sink: suspend or resume a sink'
355 'suspend-source: suspend or resume a source'
356 'suspend: suspend all sinks and sources'
357 'move-sink-input: move a stream to a sink'
358 'move-source-output: move a recording stream to a source'
359 'update-sink-proplist: update the properties of a sink'
360 'update-source-proplist: update the properties of a source'
361 'update-sink-input-proplist: update the properties of a sink-input'
362 'update-source-output-proplist: update the properties of a source-output'
363 'list-samples: list samples'
364 'play-sample: play the specified sample from the sample cache' # TODO
365 'remove-sample: remove the specified sample from the sample cache' # TODO
366 'load-sample: upload a sound from a file into the sample cache'
367 'load-sample-lazy: lazily upload a sound file into the sample cache'
368 'load-sample-dir-lazy: lazily upload all sound files in a directory into the sample cache'
369 'kill-client: kill a client'
370 'kill-sink-input: kill a sink input'
371 'kill-source-output: kill a source output'
372 'set-log-target: change the log target'
373 'set-log-level: change the log level'
374 'set-log-meta: show source code location in log messages'
375 'set-log-time: show timestamps in log messages'
376 'set-log-backtrace: show backtrace in log messages'
377 'play-file: play a sound file'
378 'dump: show daemon configuration'
379 'dump-volumes: show the state of all volumes'
380 'shared: show shared properties'
381 'exit: ask the PulseAudio daemon to exit'
382 )
383 _describe 'pacmd commands' _pacmd_commands
384 }
385
386 _arguments -C \
387 - '(help)' \
388 {-h,--help}'[display this help and exit]' \
389 '--version[show version and exit]' \
390 '::pacmd commands:_pacmd_command' \
391
392 case $words[$((CURRENT - 1))] in
393 set-card-profile) _cards;;
394 set-sink-*) _devices;;
395 set-source-*) _devices;;
396 load-module) _all_modules;;
397 describe-module) _all_modules;;
398 unload-module) _loaded_modules;;
399 suspend-*) _devices;;
400 move-*) _devices;;
401 set-port-latency-offset) _cards;;
402 load-sample*) _files;;
403 kill-client) _clients;;
404 kill-(sink|source)-*) _devices;;
405 set-log-target) compadd null auto syslog stderr file:;;
406 set-log-*) compadd true false;;
407 play-file) _files;;
408 esac
409
410 case $words[$((CURRENT - 2))] in
411 set-card-profile) _profiles;;
412 set-(sink|source)-port) _ports;;
413 set-port-latency-offset) _ports;;
414 set-*-mute) compadd true false;;
415 suspend-*) compadd true false;;
416 move-*) _devices;;
417 esac
418 }
419
420 _pasuspender_completion() {
421 _arguments -C \
422 {-h,--help}'[display this help and exit]' \
423 '--version[show version and exit]' \
424 {-s,--server}'[name of server to connect to]:host:_hosts' \
425 }
426
427 _padsp_completion() {
428 _arguments -C \
429 '-h[display this help and exit]' \
430 '-s[name of server to connect to]:host:_hosts' \
431 '-n[client name to use]:name:' \
432 '-m[stream name to use]:name:' \
433 '-M[disable /dev/mixer emulation]' \
434 '-S[disable /dev/sndstat emulation]' \
435 '-D[disable /dev/dsp emulation]' \
436 '-d[enable debug output]' \
437 '--[disable further command line parsing]' \
438 }
439
440 # TODO channel map completion
441 _pacat_completion() {
442 _pacat_sample_formats=('s16le' 's16be' 'u8' 'float32le' 'float32be'
443 'ulaw' 'alaw' 's32le' 's32be' 's24le' 's24-32le' 's24-32be')
444
445 _arguments -C \
446 {-h,--help}'[display this help and exit]' \
447 '--version[show version and exit]' \
448 {-r,--record}'[create a connection for recording]' \
449 {-p,--playback}'[create a connection for playback]' \
450 {-s,--server=}'[name of server to connect to]:host:_hosts' \
451 {-d,--device=}'[name of sink/source to connect to]:device:_devices' \
452 {-n,--client-name=}'[client name to use]:name' \
453 '--stream-name=[how to call this stream]:name' \
454 '--volume=[initial volume to use]:volume' \
455 '--rate=[sample rate to use]:rate:(44100 48000 96000)' \
456 '--format=[sample type to use]:format:((${(q)_pacat_sample_formats}))' \
457 '--channels=[number of channels to use]:number:(1 2)' \
458 '--channel-map=[channel map to use]:map' \
459 '--fix-format[use the sample format of the sink]' \
460 '--fix-rate[use the rate of the sink]' \
461 '--fix-channels[channel map of the sink]' \
462 '--no-remix[do not upmix or downmix channels]' \
463 '--no-remap[map channels by index instead of name]' \
464 '--latency=[request the specified latency]:bytes' \
465 '--process-time=[request the specified process time]:bytes' \
466 '--latency-msec=[request the specified latency in msec]:msec' \
467 '--process-time-msec=[request the specified process time in msec]:msec' \
468 '--property=[set the specified property]:property' \
469 '--raw[record/play raw PCM data]' \
470 '--passthrough[passtrough data]' \
471 '--file-format[record/play formatted PCM data]:format:_pacat_file_formats' \
472 '--list-file-formats[list available formats]' \
473 }
474
475 # TODO log-target file completion
476 _pulseaudio_completion() {
477 _arguments -C \
478 {-h,--help}'[display this help and exit]' \
479 '--version[show version and exit]' \
480 '--dump-conf[show default configuration]' \
481 '--dump-modules[show available modules]' \
482 '--dump-resample-methods[show available resample methods]' \
483 '--cleanup-shm[cleanup shared memory]' \
484 '--start[start the daemon]' \
485 {-k,--kill}'[kill a running daemon]' \
486 '--check[check for a running daemon]' \
487 '--system=[run as systemd-wide daemon]:bool:(true false)' \
488 {-D,--daemonize=}'[daemonize after startup]:bool:(true false)' \
489 '--fail=[quit when startup fails]:bool:(true false)' \
490 '--high-priority=[try to set high nice level]:bool:(true false)' \
491 '--realtime=[try to enable rt scheduling]:bool:(true false)' \
492 '--disallow-module-loading=[disallow module loading]:bool:(true false)' \
493 '--disallow-exit=[disallow user requested exit]' \
494 '--exit-idle-time=[terminate the daemon on passed idle time]:time' \
495 '--scache-idle-time=[unload autoloaded samples on passed idle time]:time' \
496 '--log-level=[set the verbosity level]:level' \
497 '-v[increase the verbosity level]' \
498 '--log-target=[set the log target]:target:(auto syslog stderr file\: new_file\:):file' \
499 '--log-meta=[include code location in log messages]:bool:(true false)' \
500 '--log-time=[include timestamps in log messages]:bool:(true false)' \
501 '--log-backtrace=[include backtrace in log messages]:frames' \
502 {-p,--dl-search-path=}'[set the search path for plugins]:dir:_files' \
503 '--resample-method=[set the resample method]:method:_resample_methods' \
504 '--use-pid-file=[create a PID file]:bool:(true false)' \
505 '--no-cpu-limit=[do not install CPU load limiter]:bool:(true false)' \
506 '--disable-shm=[disable shared memory support]:bool:(true false)' \
507 {-L,--load=}'[load the specified module]:modules:_all_modules' \
508 {-F,--file=}'[run the specified script]:file:_files' \
509 '-C[open a command line on the running tty]' \
510 '-n[do not load the default script file]' \
511 }
512
513 _pulseaudio() {
514 local state line curcontext="$curcontext"
515
516 case $service in
517 pulseaudio) _pulseaudio_completion;;
518 pactl) _pactl_completion;;
519 pacmd) _pacmd_completion;;
520 pacat) _pacat_completion;;
521 paplay)_pacat_completion;;
522 parecord)_pacat_completion;;
523 padsp) _padsp_completion;;
524 pasuspender) _pasuspender_completion;;
525 *) _message "Err";;
526 esac
527 }
528
529 _pulseaudio "$@"
530
531 #vim: set ft=zsh sw=4 ts=4 noet