From b517b4398dbff84d661b059d27291cefde5ff845 Mon Sep 17 00:00:00 2001 From: Robin Ebert Date: Tue, 6 Jan 2026 16:34:47 +0100 Subject: [PATCH] shell-completion: fix bash completion if a profile or a port contains spaces --- shell-completion/bash/pactl | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/shell-completion/bash/pactl b/shell-completion/bash/pactl index 050fe7d58..96992fa40 100644 --- a/shell-completion/bash/pactl +++ b/shell-completion/bash/pactl @@ -48,7 +48,7 @@ __ports () { flag { if (/^\t\t[A-Za-z]/) - ports = ports substr($0, 3, index($0, ":")-3) " " + ports = ports substr($0, 3, index($0, ":")-3) "\n" } END { @@ -68,7 +68,7 @@ __profiles () { flag { if (/^\t\t[A-Za-z]/) - profiles = profiles substr($0, 3, index($0, ": ")-3) " " + profiles = profiles substr($0, 3, index($0, ": ")-3) "\n" } END { @@ -108,6 +108,20 @@ in_array() { done } +_profiles_helper() { + local IFS=$'\n' + comps="$(__profiles)" + COMPREPLY=($(compgen -W '${comps[*]}' -- "$1")) + compopt -o fullquote +} + +_ports_helper() { + local IFS=$'\n' + comps="$(__ports)" + COMPREPLY=($(compgen -W '${comps[*]}' -- "$1")) + compopt -o fullquote +} + _pactl() { local cur prev words cword preprev word command local comps @@ -153,13 +167,11 @@ _pactl() { ;; set-card-profile) - comps=$(__profiles) - COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur")) + _profiles_helper "$cur" ;; set-*-port) - comps=$(__ports) - COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur")) + _ports_helper "$cur" ;; set-*-mute) COMPREPLY=($(compgen -W 'true false toggle' -- "$cur")) ;; @@ -168,8 +180,7 @@ _pactl() { ;; #TODO set-port-*) - comps=$(__ports) - COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur")) + _ports_helper "$cur" ;; --server) compopt +o nospace @@ -304,13 +315,11 @@ _pacmd() { ;; set-card-profile) - comps=$(__profiles) - COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur")) + _profiles_helper "$cur" ;; set-*port*) - comps=$(__ports) - COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur")) + _ports_helper "$cur" ;; set-*-mute) COMPREPLY=($(compgen -W 'true false' -- "$cur"));;