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