code cleanup of completion logic

This commit is contained in:
Tilman Kranz
2025-05-18 05:20:16 +02:00
parent 4574f37340
commit 0e1a4c4534

View File

@ -1,10 +1,11 @@
_pulseaudio_tcp_completions() { _pulseaudio_tcp_completions() {
local cur options commands delete all_options command_pattern all_commands local options commands cur delete all_options command_pattern all_commands
cur=${COMP_WORDS[COMP_CWORD]}
options=( "--debug" "--help" "--nogui" ) options=( "--debug" "--help" "--nogui" )
commands=( "start" "stop" "status" "setup" "restart" ) commands=( "start" "stop" "status" "setup" "restart" )
cur=${COMP_WORDS[COMP_CWORD]}
for delete in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}" ; do for delete in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}" ; do
options=("${options[@]/$delete}") options=("${options[@]/$delete}")
commands=("${commands[@]/$delete}") commands=("${commands[@]/$delete}")
@ -21,13 +22,7 @@ _pulseaudio_tcp_completions() {
all_commands="${commands[*]}" all_commands="${commands[*]}"
fi fi
COMPREPLY=() mapfile -t COMPREPLY < <(compgen -W "$all_options $all_commands" "$cur")
case "$cur" in
'') mapfile -t COMPREPLY < <(compgen -W "$all_options $all_commands" -- "$cur") ;;
-*) mapfile -t COMPREPLY < <(compgen -W "$all_options" -- "$cur") ;;
[^-]*) mapfile -t COMPREPLY < <(compgen -W "$all_commands" -- "$cur") ;;
esac
return 0 return 0
} && complete -F _pulseaudio_tcp_completions pulseaudio-tcp } && complete -F _pulseaudio_tcp_completions pulseaudio-tcp