Integrating Homebrew bash completion on Linux with system completions
I like to use Homebrew on my Linux development machine as well, instead of random apt packages which may or may not be up to date for common tools.
One annoyance I found a solution for, is getting the bash completion for Homebrew commands to work on Linux. The problem is that Ubuntu (and other Linux distributions) have their own bash completion scripts for system commands. But the way most bash completion scripts work is that they have a check to see if completions are already loaded.
So if I have a line in my bashrc to load homebrew completions, it won’t load, because it detects the completions from
the system already loaded. Specifically, it looks for the environment variable BASH_COMPLETION_VERSINFO which is set
by any bash completion script that is already loaded.
Solution
The only satisfactory solution I found is to disable the bash completion for system commands.
My only concern was that I might lose completions for system commands. However, it seems the Homebrew completion loader also checks for system completion scripts.
You can verify that it works here:
complete -p for a command will only show the completion function if you have exercised the completion for the command once using COMMAND<TAB><TAB>.