brew: bash completions broken on macOS

1

I am using following bash completions installed via brew: bash-completion and bash-completion@2. My .bashrc looks like:

if [ -f /usr/local/share/bash-completion/bash_completion ]; then
. /usr/local/share/bash-completion/bash_completion
fi


if [ -f /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion ]; then
  BASH_COMPLETION=/usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
  . /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
fi

The problem is when I press TAB on keyboard I get the error:

-bash: words: bad array subscript

What is the problem here? How can I fix it?

Update 1: After removing /usr/local/share/bash-completion/bash_completion from .bashrc error doesn't happen but I miss out on many completions.

Xolve

Posted 2017-08-05T06:13:06.890

Reputation: 450

Answers

0

The solution is that I should call bash completion from 1.3.2 before bash-completion@2. Following is how my .bashrc looks, and this solves the problem:

if [ -f /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion ]; then
  BASH_COMPLETION=/usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
  . /usr/local/Cellar/bash-completion/1.3_2/etc/bash_completion
fi

if [ -f /usr/local/share/bash-completion/bash_completion ]; then
    . /usr/local/share/bash-completion/bash_completion
fi

Xolve

Posted 2017-08-05T06:13:06.890

Reputation: 450

0

The new proper way is add the following line to your ~/.bash_profile::

[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Ben

Posted 2017-08-05T06:13:06.890

Reputation: 1