shell-completion: fix bash completion if a profile or a port contains spaces

This commit is contained in:
Robin Ebert 2026-01-06 16:34:47 +01:00
parent b096704c0d
commit b517b4398d
No known key found for this signature in database
GPG key ID: 8B6531570DC10850

View file

@ -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"));;