_pulseaudio_tcp_completions() { local cur options commands delete no_cmd cur=${COMP_WORDS[COMP_CWORD]} options=( "--debug" "--help" "--nogui" ) commands=( "start" "stop" "status" "setup" "restart" ) for delete in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}" ; do options=("${options[@]/$delete}") 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 "$all_options $all_commands" -- "$cur") ;; -*) mapfile -t COMPREPLY < <(compgen -W "$all_options" -- "$cur") ;; [^-]*) mapfile -t COMPREPLY < <(compgen -W "$all_commands" -- "$cur") ;; esac return 0 } && complete -F _pulseaudio_tcp_completions pulseaudio-tcp