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