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() { _pulseaudio_tcp_completions() {
local \ local \
all_commands \ command_list \
all_options \
command_pattern \ command_pattern \
commands \ commands \
cur \ cur \
delete \ option_list \
options options \
word
options=( "--debug" "--help" "--nogui" ) options=( "--debug" "--help" "--nogui" )
commands=( "start" "stop" "status" "setup" "restart" ) commands=( "start" "stop" "status" "setup" "restart" )
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
for delete in "${COMP_WORDS[@]}" ; do for word in "${COMP_WORDS[@]}" ; do
[[ $delete = "$cur" ]] && continue [[ $word = "$cur" ]] && continue
options=("${options[@]/$delete}") options=("${options[@]/$word}")
commands=("${commands[@]/$delete}") commands=("${commands[@]/$word}")
done done
all_options="${options[*]}" option_list="${options[*]}"
printf -v command_pattern "%s|" "${commands[@]}" printf -v command_pattern "%s|" "${commands[@]}"
command_pattern="(${command_pattern%?})" command_pattern="(${command_pattern%?})"
if [[ ${COMP_WORDS[*]} =~ $command_pattern ]] ; then if [[ ${COMP_WORDS[*]} =~ $command_pattern ]] ; then
all_commands="" command_list=""
else else
all_commands="${commands[*]}" command_list="${commands[*]}"
fi fi
mapfile -t COMPREPLY < <( mapfile -t COMPREPLY < <( compgen -W "$option_list $command_list" -- "$cur")
compgen \
-W "$all_options $all_commands" \
-- "$cur"
)
return 0 return 0
} }