- the currently edited word should be omitted when removing duplicate completion suggestions, which is not necessarily the last word - when using "compgen", mark "$cur" as non-option argument - some formatting cleanup
45 lines
903 B
Bash
45 lines
903 B
Bash
_pulseaudio_tcp_completions() {
|
|
local \
|
|
all_commands \
|
|
all_options \
|
|
command_pattern \
|
|
commands \
|
|
cur \
|
|
delete \
|
|
options
|
|
|
|
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}")
|
|
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
|
|
|
|
mapfile -t COMPREPLY < <(
|
|
compgen \
|
|
-W "$all_options $all_commands" \
|
|
-- "$cur"
|
|
)
|
|
|
|
return 0
|
|
}
|
|
|
|
complete -F _pulseaudio_tcp_completions pulseaudio-tcp
|
|
|
|
# vim:et ft=bash sw=2 ts=2
|