This varies depending on your platform and/or versions of bash and bash-completion. For example:
Ubuntu
On Ubuntu 20.04 the file /etc/bash_completion
does this:
. /usr/share/bash-completion/bash_completion
And in that file I find
for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do
dirs+=( $dir/bash-completion/completions )
done
Which indicates that /usr/local/share/bash-completion/completions
is scanned for completion scripts. Empirical experiments supports this.
MacOS/Brew
I could not find anything about bash completion in /etc
or /usr/share
on my MacOS 11.2.3. Which indicates that bare Darwin does not have bash completion, which makes sense since Apple have left Bash at 3.2 because of licensing. Might have for zsh
, though, I didn't look.
/usr/local/etc/bash-completion.d
, which you reference, is a part of the Homebrew installation under /usr/local
. In there I found some completion scripts, but not the activation script. You should not have to activate those explicitly yourself.
I did find /usr/local/share/bash-completion
, again from Homebrew
, and it has the script bash_completion
. In it are the same lines as Ubuntu, which also makes sense since Homebrew
is kinda complete "GNU" but under /usr/local
. But it also reference the directory /usr/local/etc/bash-completion.d
. Sourcing /usr/local/share/bash-completion/bash_completion
added the completion from that directory also.
But /usr/local/share/bash-completion/bash_completion
is not executed by default, so you have to add that to your ~/bash_profile
or ~/profile
as described here. It also describes how to handle zsh
and fish
.
Cygwin
Cygwin
is another Posix-compliant environment which has bash completion. (I haven't checked if bash completion is part of the Posix standard, though) After installing the bash-completion
package there is /usr/share/bash-completion/bash_completion
as Ubuntu and Homebrew has. Here there is no /etc/bash_completion
and as the ~/.bashrc
I had (generated long ago) did only look for this completions wasn't activated.
Summary
Many GNU-like environments support bash_completion but you might have to
- install a package
- ensure that it is sourced when you log in, which is not always the case by default
If it is not activated by default in your environment, you can activate it by sourcing the "root" script (in /etc
, /usr/share/bash-completion
or where it might be located) from your .bashrc
, bash_profile
or similar.
I'm guessing YMMV for all other possible platforms (other Linux distros, MSYS2 etc.) but the above might help you to figure out how to enable completion. Which is really helpful when available.
/etc/bash_completion.d/
? – Gorges/usr/local/etc/bash_completion.d
dir – Glottissource
ing the completion scripts oreval
ing them? – Glottis