diff --git a/pulseaudio-tcp.bash_completion b/pulseaudio-tcp.bash_completion index 18f95eb..522b513 100644 --- a/pulseaudio-tcp.bash_completion +++ b/pulseaudio-tcp.bash_completion @@ -1,40 +1,36 @@ _pulseaudio_tcp_completions() { local \ - all_commands \ - all_options \ + command_list \ command_pattern \ commands \ cur \ - delete \ - options + option_list \ + options \ + word options=( "--debug" "--help" "--nogui" ) commands=( "start" "stop" "status" "setup" "restart" ) cur=${COMP_WORDS[COMP_CWORD]} - for delete in "${COMP_WORDS[@]}" ; do - [[ $delete = "$cur" ]] && continue - options=("${options[@]/$delete}") - commands=("${commands[@]/$delete}") + for word in "${COMP_WORDS[@]}" ; do + [[ $word = "$cur" ]] && continue + options=("${options[@]/$word}") + commands=("${commands[@]/$word}") done - all_options="${options[*]}" + option_list="${options[*]}" printf -v command_pattern "%s|" "${commands[@]}" command_pattern="(${command_pattern%?})" if [[ ${COMP_WORDS[*]} =~ $command_pattern ]] ; then - all_commands="" + command_list="" else - all_commands="${commands[*]}" + command_list="${commands[*]}" fi - mapfile -t COMPREPLY < <( - compgen \ - -W "$all_options $all_commands" \ - -- "$cur" - ) + mapfile -t COMPREPLY < <( compgen -W "$option_list $command_list" -- "$cur") return 0 }