From cf4477bb1c3d352526d1641d04a386c8930899f0 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 18 May 2025 02:03:47 +0200 Subject: [PATCH] completion suggests only one command verb --- pulseaudio-tcp.bash_completion | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pulseaudio-tcp.bash_completion b/pulseaudio-tcp.bash_completion index cb46126..3e4a4d8 100644 --- a/pulseaudio-tcp.bash_completion +++ b/pulseaudio-tcp.bash_completion @@ -1,5 +1,5 @@ _pulseaudio_tcp_completions() { - local cur options commands delete + local cur options commands delete no_cmd cur=${COMP_WORDS[COMP_CWORD]} options=( "--debug" "--help" "--nogui" ) @@ -10,12 +10,23 @@ _pulseaudio_tcp_completions() { commands=("${commands[@]/$delete}") done + all_options="${options[*]}" + + printf -v command_pattern "%s|" "${commands[@]}" + command_pattern="(${command_pattern%?})" + + if [[ ${COMP_WORDS[*]} =~ $command_pattern ]] ; then + all_commands="" + else + all_commands="${commands[*]}" + fi + COMPREPLY=() case "$cur" in - '') mapfile -t COMPREPLY < <(compgen -W "${options[*]} ${commands[*]}" -- "$cur") ;; - -*) mapfile -t COMPREPLY < <(compgen -W "${options[*]}" -- "$cur") ;; - [^-]*) mapfile -t COMPREPLY < <(compgen -W "${commands[*]}" -- "$cur") ;; + '') 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