I have installed bash-completion via homebrew and added the code below to .bash_profile

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion

Bash completion does not work, even though there are many valid bash-completion scripts in /usr/local/etc/bash_completion.d

$ ls /usr/local/etc/bash_completion.d
abook               mc
adb-completion.bash     mcrypt
ant             mdadm
apache2ctl          medusa
apt             minicom
apt-build           mkinitrd
aptitude            module-init-tools

When executing bash-completion manually in a bash prompt, I get the error

$ [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
-bash: .: /Users/hanxue/.bash_completion: is a directory
$ source /usr/local/etc/bash_completion
-bash: .: /Users/hanxue/.bash_completion: is a directory

closed as off-topic by Jeff Schaller, Anthon, sebasth, Stephen Rauch, Kusalananda Oct 8 '17 at 16:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, sebasth, Stephen Rauch, Kusalananda
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Simply run brew install bash-completion then edit your bash_profile – GAD3R Oct 7 '17 at 13:33

Turned out that I have a ~/.bash_completion directory, when the bash-completion script is expecting a file.

Deleting the directory solved the problem, and bash-completion is now working

$ ls -ld ~/.bash_completion/
drwxr-xr-x  3 hanxue  staff  102 Oct  1  2013 /Users/hanxue/.bash_completion/
$ rm -R ~/.bash_completion
$ [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

Looking at the bash-completion source code, I found this line

# source user completion file
[[ $BASH_COMPLETION != ~/.bash_completion && -r ~/.bash_completion ]] \
    && . ~/.bash_completion

Not the answer you're looking for? Browse other questions tagged or ask your own question.