fix some inconsistencies

- the currently edited word should be omitted when removing
   duplicate completion suggestions, which is not necessarily
   the last word
 - when using "compgen", mark "$cur" as non-option argument
 - some formatting cleanup
This commit is contained in:
Tilman Kranz
2025-05-18 06:17:02 +02:00
parent 0e1a4c4534
commit a75dbb9c84

View File

@ -1,12 +1,20 @@
_pulseaudio_tcp_completions() {
local options commands cur delete all_options command_pattern all_commands
local \
all_commands \
all_options \
command_pattern \
commands \
cur \
delete \
options
options=( "--debug" "--help" "--nogui" )
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[@]}" ; do
[[ $delete = "$cur" ]] && continue
options=("${options[@]/$delete}")
commands=("${commands[@]/$delete}")
done
@ -22,7 +30,15 @@ _pulseaudio_tcp_completions() {
all_commands="${commands[*]}"
fi
mapfile -t COMPREPLY < <(compgen -W "$all_options $all_commands" "$cur")
mapfile -t COMPREPLY < <(
compgen \
-W "$all_options $all_commands" \
-- "$cur"
)
return 0
} && complete -F _pulseaudio_tcp_completions pulseaudio-tcp
}
complete -F _pulseaudio_tcp_completions pulseaudio-tcp
# vim:et ft=bash sw=2 ts=2