From a75dbb9c848609a1c4f28675242d0cc11a3dacdd Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 18 May 2025 06:17:02 +0200 Subject: [PATCH] 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 --- pulseaudio-tcp.bash_completion | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pulseaudio-tcp.bash_completion b/pulseaudio-tcp.bash_completion index 2b18a1e..18f95eb 100644 --- a/pulseaudio-tcp.bash_completion +++ b/pulseaudio-tcp.bash_completion @@ -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