slight code cleanup

This commit is contained in:
Tilman Kranz
2025-05-18 15:39:50 +02:00
parent a75dbb9c84
commit b4a6c4c4cf

View File

@ -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
}