An Introduction to Programmable Completion in Bash

Installing the Completion

On most modern Linux distributions, the location to store completion definitions for specific commands has been unified to the path /usr/share/bash-completion/completions. The completion file is expected to have the name of the command, i.e. we should store our bash script containing the function definition and complete -F … command to a file /usr/share/bash-completion/completions/pulseaudio-tcp.

You can also test this with the completion file from the project’s source code:

curl \
  https://tk-sls.de/git/tk-sls.de/pulseaudio-tcp/raw/branch/main/pulseaudio-tcp.bash_completion \
  | sudo tee /usr/share/bash-completion/completions/pulseaudio-tcp

To test if this file is working correctly, source the file into your current Bash session:

. /usr/share/bash-completion/completions/pulseaudio-tcp

To confirm that the completion definition from now on applies automatically, start a new instance of Bash and test if parameters are completed correctly.