Files
pulseaudio-tcp/pulseaudio-tcp.bash_completion
2025-05-18 02:18:30 +02:00

34 lines
988 B
Plaintext

_pulseaudio_tcp_completions() {
local cur options commands delete all_options command_pattern all_commands
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