[pulseaudio-commits] 6 commits - shell-completion/zsh
Tanu Kaskinen
tanuk at kemper.freedesktop.org
Sat Aug 16 23:31:09 PDT 2014
shell-completion/zsh/_pulseaudio | 122 +++++++++++++++------------------------
1 file changed, 49 insertions(+), 73 deletions(-)
New commits:
commit 64d17a6b0a074970a3ab893f79690a7ab04aabcd
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Sat Aug 16 14:48:19 2014 +0300
shell-completion: zsh: Add "=" to the end of some command options
Without the equals sign, only the "--server foo" form is recognized,
so the "--server=foo" form doesn't get completion support.
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index 77abe2b..1c786dc 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -278,8 +278,8 @@ _pactl_completion() {
_arguments -C -S -A '-*' \
{-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
- {-s,--server}'[name of server to connect to]:host:_hosts' \
- {-n,--client-name}'[client name to use]:name' \
+ {-s,--server=}'[name of server to connect to]:host:_hosts' \
+ {-n,--client-name=}'[client name to use]:name' \
'::pactl command:_pactl_command'
case $words[$((CURRENT - 1))] in
@@ -406,7 +406,7 @@ _pasuspender_completion() {
_arguments -S -A "-*" -C \
{-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
- {-s,--server}'[name of server to connect to]:host:_hosts' \
+ {-s,--server=}'[name of server to connect to]:host:_hosts' \
}
_padsp_completion() {
commit db6d5011cd03a8841614b729fecc9c612a4ed10a
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Sat Aug 16 14:48:18 2014 +0300
shell-completion: zsh: Use -S and -A with _arguments
-S makes the option parser to not try parsing arguments as options
after "--" has appeared in the command line.
-A "-*" makes the option parser to not try parsing arguments as
options after the first non-option argument. The "-*" pattern means
that if there are unrecognized parameters that look like options
(i.e. start with a dash), those should not terminate the option
parsing.
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index b993e85..77abe2b 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -275,7 +275,7 @@ _pactl_completion() {
'cards: list available cards'
)
- _arguments -C \
+ _arguments -C -S -A '-*' \
{-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
{-s,--server}'[name of server to connect to]:host:_hosts' \
@@ -369,7 +369,7 @@ _pacmd_completion() {
_describe 'pacmd commands' _pacmd_commands
}
- _arguments -C \
+ _arguments -C -S -A "-*" \
{-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
'::pacmd commands:_pacmd_command' \
@@ -403,14 +403,14 @@ _pacmd_completion() {
}
_pasuspender_completion() {
- _arguments -C \
+ _arguments -S -A "-*" -C \
{-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
{-s,--server}'[name of server to connect to]:host:_hosts' \
}
_padsp_completion() {
- _arguments -C \
+ _arguments -C -S -A "-*" \
'-h[display help and exit]' \
'-s[name of server to connect to]:host:_hosts' \
'-n[client name to use]:name:' \
@@ -429,7 +429,7 @@ _pacat_completion() {
_pacat_sample_formats=('s16le' 's16be' 'u8' 'float32le' 'float32be'
'ulaw' 'alaw' 's32le' 's32be' 's24le' 's24-32le' 's24-32be')
- _arguments -C \
+ _arguments -C -S -A "-*" \
{-h,--help}'[display this help and exit]' \
'--version[show version and exit]' \
{-r,--record}'[create a connection for recording]' \
commit cd3cae9285ba18ff5159f0d407fc681acf61dbf5
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Sat Aug 16 14:48:17 2014 +0300
shell-completion: zsh: Don't use multiple option sets for one command
The options were divided to multiple sets to prevent (or at least try
to prevent) completing e.g. --server after -s was already given. This,
however, caused problems, because after the user had written
"pactl --server foo", further completions stopped to work. The
"server" option set didn't contain any other options, so once Zsh
detected that the "server" option set was in use, it thought that no
other options were valid.
The special casing for "-s", "-n", "--server" and "--client-*" at the
end of _pactl_completion() was probably an attempt to deal with this
problem. Those special cases are unnecessary now that the option
specification given to _arguments is more correct.
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index d58ab47..b993e85 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -276,14 +276,11 @@ _pactl_completion() {
)
_arguments -C \
- - '(help)' \
- {-h,--help}'[display help and exit]' \
+ {-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
- - '(server)' \
- {-s,--server}'[name of server to connect to]:host:_hosts' \
- - '(name)' \
- {-n,--client-name}'[client name to use]:name' \
- '::pactl commands:_pactl_command' \
+ {-s,--server}'[name of server to connect to]:host:_hosts' \
+ {-n,--client-name}'[client name to use]:name' \
+ '::pactl command:_pactl_command'
case $words[$((CURRENT - 1))] in
list) _describe 'pactl list commands' _pactl_list_commands;;
@@ -307,8 +304,6 @@ _pactl_completion() {
suspend-*) compadd true false;;
list) compadd short;;
move-*) _devices;;
- '-s' | '-n') _pactl_command;;
- --server | --client-*) _pactl_command;;
esac
}
@@ -375,8 +370,7 @@ _pacmd_completion() {
}
_arguments -C \
- - '(help)' \
- {-h,--help}'[display help and exit]' \
+ {-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
'::pacmd commands:_pacmd_command' \
commit 74c724db05f278650bff95d9a937c687c8e25373
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Sat Aug 16 14:48:16 2014 +0300
shell-completion: zsh: Don't say "this help" when it's a different help
The option descriptions that Zsh prints are not the same thing as the
help text that pactl, pacmd etc. print when given --help.
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index 6ff8ec1..d58ab47 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -277,7 +277,7 @@ _pactl_completion() {
_arguments -C \
- '(help)' \
- {-h,--help}'[display this help and exit]' \
+ {-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
- '(server)' \
{-s,--server}'[name of server to connect to]:host:_hosts' \
@@ -376,7 +376,7 @@ _pacmd_completion() {
_arguments -C \
- '(help)' \
- {-h,--help}'[display this help and exit]' \
+ {-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
'::pacmd commands:_pacmd_command' \
@@ -410,14 +410,14 @@ _pacmd_completion() {
_pasuspender_completion() {
_arguments -C \
- {-h,--help}'[display this help and exit]' \
+ {-h,--help}'[display help and exit]' \
'--version[show version and exit]' \
{-s,--server}'[name of server to connect to]:host:_hosts' \
}
_padsp_completion() {
_arguments -C \
- '-h[display this help and exit]' \
+ '-h[display help and exit]' \
'-s[name of server to connect to]:host:_hosts' \
'-n[client name to use]:name:' \
'-m[stream name to use]:name:' \
commit 1f9d4cbe933fd06e0a89cae6a64580bc8e576e30
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Sat Aug 16 14:48:15 2014 +0300
shell-completion: zsh: Support also --server in remote detection
_set_remote() is supposed to find out if a remote server has been
specified on the command line, but previously it only checked for -s
and ignored --server, causing the completion code to connect to the
local server instead when it should have connected to the remote
server to get the data for the completions.
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index 243c1b4..6ff8ec1 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -2,9 +2,11 @@
_set_remote() {
for (( i = 0; i < ${#words[@]}; i++ )) do
- if [[ ${words[$i]} == -s ]]; then
+ if [[ ${words[$i]} == -s || ${words[$i]} == --server ]]; then
remote="-s ${words[$i+1]}"
break;
+ elif [[ ${words[$i]} == --server=* ]]; then
+ remote=${words[$i]}
fi
done
}
commit 09e9d13e2d5f42cdb3118eab93fb9d24fabdfc72
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Sat Aug 16 14:48:14 2014 +0300
shell-completion: zsh: Move duplicated code into a function
This is just refactoring, no functional changes.
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index ef279f1..243c1b4 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -1,8 +1,17 @@
#compdef pulseaudio pactl pacmd pacat paplay parec parecord padsp pasuspender
+_set_remote() {
+ for (( i = 0; i < ${#words[@]}; i++ )) do
+ if [[ ${words[$i]} == -s ]]; then
+ remote="-s ${words[$i+1]}"
+ break;
+ fi
+ done
+}
+
_devices() {
local -a _device_list
- local cmd _device _device_description _remote_cmd
+ local cmd _device _device_description
if [[ $service == pactl || $service == pacmd ]]; then
case $words[$((CURRENT - 1))] in
@@ -55,15 +64,8 @@ _devices() {
fi
- for (( i = 0; i < ${#words[@]}; i++ )) do
- if [[ ${words[$i]} == -s ]]; then
- _remote_cmd="-s ${words[$i+1]}"
- break;
- fi
- done
-
for target in $cmd; do
- for device_info in ${(ps:\n\n:)"$(_call_program device_tag "pactl $_remote_cmd list $target 2> /dev/null")"}; do
+ for device_info in ${(ps:\n\n:)"$(_call_program device_tag "pactl $remote list $target 2> /dev/null")"}; do
for line in ${(f)device_info}; do
if [[ $target == (sink-inputs|source-outputs) ]]; then
if [[ $line == (Sink*Input|Source*Output)* ]]; then
@@ -98,18 +100,11 @@ _devices() {
_profiles() {
local -a _profile_list
- local _current_card _raw_profiles _profile_name _profile_description _remote_cmd
+ local _current_card _raw_profiles _profile_name _profile_description
_current_card=$words[$((CURRENT - 1))]
- for (( i = 0; i < ${#words[@]}; i++ )) do
- if [[ ${words[$i]} == -s ]]; then
- _remote_cmd="-s ${words[$i+1]}"
- break;
- fi
- done
-
- for card in ${(ps:\n\n:)"$(_call_program profiles_tag "pactl $_remote_cmd list cards 2> /dev/null")"}; do
+ for card in ${(ps:\n\n:)"$(_call_program profiles_tag "pactl $remote list cards 2> /dev/null")"}; do
if [[ $card == *$_current_card* ]]; then
_raw_profiles=${card##*Profiles:}
_raw_profiles=${_raw_profiles%%Active Profile:*}
@@ -130,7 +125,7 @@ _profiles() {
_ports() {
local -a _port_list
- local _raw_ports _port_name _port_description _current_device _remote_cmd
+ local _raw_ports _port_name _port_description _current_device
case $words[$((CURRENT - 2))] in
set-sink-port) cmd="sinks";;
@@ -140,14 +135,7 @@ _ports() {
_current_device=$words[$((CURRENT - 1))]
- for (( i = 0; i < ${#words[@]}; i++ )) do
- if [[ ${words[$i]} == -s ]]; then
- _remote_cmd="-s ${words[$i+1]}"
- break;
- fi
- done
-
- for device in ${(ps:\n\n:)"$(_call_program port_tag "pactl $_remote_cmd list $cmd 2> /dev/null")"}; do
+ for device in ${(ps:\n\n:)"$(_call_program port_tag "pactl $remote list $cmd 2> /dev/null")"}; do
if [[ $device == *Ports:* && $device == *$_current_device* ]]; then
_raw_ports=${device##*Ports:}
_raw_ports=${_raw_ports%%Active Port:*}
@@ -168,16 +156,9 @@ _ports() {
_cards(){
local -a _card_list
- local _card _cad_name _remote_cmd
-
- for (( i = 0; i < ${#words[@]}; i++ )) do
- if [[ ${words[$i]} == -s ]]; then
- _remote_cmd="-s ${words[$i+1]}"
- break;
- fi
- done
+ local _card _cad_name
- for card_info in ${(ps:\n\n:)"$(_call_program card_tag "pactl $_remote_cmd list cards 2> /dev/null")"}; do
+ for card_info in ${(ps:\n\n:)"$(_call_program card_tag "pactl $remote list cards 2> /dev/null")"}; do
for line in ${(f)card_info}; do
if [[ $line == *Name:* ]]; then
_card=${line#*: }
@@ -201,16 +182,9 @@ _all_modules(){
}
_loaded_modules(){
- local -a _loaded_modules_list _remote_cmd
+ local -a _loaded_modules_list
- for (( i = 0; i < ${#words[@]}; i++ )) do
- if [[ ${words[$i]} == -s ]]; then
- _remote_cmd="-s ${words[$i+1]}"
- break;
- fi
- done
-
- for module in ${(f)"$(_call_program modules_tag "pactl $_remote_cmd list modules short 2> /dev/null")"}; do
+ for module in ${(f)"$(_call_program modules_tag "pactl $remote list modules short 2> /dev/null")"}; do
_loaded_modules_list+=(${${(ps:\t:)module}[1]}:${${(ps:\t:)module}[2]})
done
_describe 'module list' _loaded_modules_list
@@ -226,16 +200,9 @@ _resample_methods() {
_clients() {
local -a _client_list
- local _client _client_description _remote_cmd
+ local _client _client_description
- for (( i = 0; i < ${#words[@]}; i++ )) do
- if [[ ${words[$i]} == -s ]]; then
- _remote_cmd="-s ${words[$i+1]}"
- break;
- fi
- done
-
- for client_info in ${(ps:\n\n:)"$(_call_program clients_tag "pactl $_remote_cmd list clients 2> /dev/null")"}; do
+ for client_info in ${(ps:\n\n:)"$(_call_program clients_tag "pactl $remote list clients 2> /dev/null")"}; do
for line in ${(f)client_info}; do
if [[ $line == Client[[:space:]]#* ]]; then
_client=${line#*\#}
@@ -257,6 +224,8 @@ _pacat_file_formats() {
}
_pactl_completion() {
+ _set_remote
+
_pactl_command(){
_pactl_commands=(
'help: show help and exit'
@@ -459,6 +428,8 @@ _padsp_completion() {
# TODO channel map completion
_pacat_completion() {
+ _set_remote
+
_pacat_sample_formats=('s16le' 's16be' 'u8' 'float32le' 'float32be'
'ulaw' 'alaw' 's32le' 's32be' 's24le' 's24-32le' 's24-32be')
@@ -535,6 +506,15 @@ _pulseaudio_completion() {
_pulseaudio() {
local state line curcontext="$curcontext"
+ # Some commands, like pactl and pacat, have an option for specifying the
+ # server address, like "--server=somehost". If that option is set, then the
+ # helper commands that are run as part of the autocompletion need to use
+ # that same option. The option is saved in this variable in _set_remote(),
+ # which is called in the beginning of _pactl_completion() and others. The
+ # autocompletion commands can then find the option in that variable if the
+ # option is set.
+ local remote
+
case $service in
pulseaudio) _pulseaudio_completion;;
pactl) _pactl_completion;;
More information about the pulseaudio-commits
mailing list