Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Homebrew Shell Completion" instructions not working on macOS 10.14.2 #5610

Closed
samuela opened this issue Jan 25, 2019 · 22 comments
Closed

"Homebrew Shell Completion" instructions not working on macOS 10.14.2 #5610

samuela opened this issue Jan 25, 2019 · 22 comments
Labels
outdated PR was locked due to age

Comments

@samuela
Copy link
Contributor

samuela commented Jan 25, 2019

I followed the bash instructions here: https://docs.brew.sh/Shell-Completion but kept getting the error

nuvemfs 🔥 source ~/.bash_profile
-bash: /usr/local/etc/bash_completion.d/*: No such file or directory

which isn't so cool. Replacing it with

if type brew 2&>/dev/null; then
    source "$(brew --prefix)/etc/bash_completion"
else
  echo "run: brew install git bash-completion"
fi

works just fine however.

@MikeMcQuaid MikeMcQuaid transferred this issue from Homebrew/brew.sh Jan 25, 2019
@MikeMcQuaid
Copy link
Member

This was changed by @iandol in #5511. @iandol could you provide some help/thoughts here? Thanks!

@iandol
Copy link
Contributor

iandol commented Jan 25, 2019

Hm, I found on both my macOS machines (both 10.14.2) and my Ubuntu 18.04 machines running Linuxbrew that the original .../etc/bash_completion was not present (thus source failed) yet I had a .../etc/bash_completion.d/ folder with several completion files within. I read around and understood this is the default path. I raised this on discourse here: https://discourse.brew.sh/t/bash-completion-and-brew-instructions-for-setting-up-completions/3808 — and Sean seemed to also think it should be bash_completion.d/

I do not know under what circumstances the brew installs the completion files in .../etc/bash_completion and when it uses .../etc/bash_completion.d

Here is where my completions are automatically put on macOS 10.14.2:

 ❯ ls $(brew --prefix)/etc/bash_completion.d/
bat.bash                        git-prompt.sh
brew                            npm
brew-services                   pandoc
git-completion.bash             youtube-dl.bash-completion

edit: I normally use zsh and do not have deep knowledge of bash...

@MikeMcQuaid
Copy link
Member

I think this may be the difference between the bash-completion formula being installed and Bash completion files being installed from individual formulae. CC @maxim-belkin who has also been talking completions lately. I don't use Bash (ZSH 4 lyfe) but want to help where I can.

@iandol
Copy link
Contributor

iandol commented Jan 25, 2019

Yes, there may be some confusion from bash-completion package vs auto installed completion files. https://docs.brew.sh/Shell-Completion is talking about the auto installed completion files, so I assume it is /bash_completion.d/ while the bash-completion package appears to use /bash_completion?

@MikeMcQuaid
Copy link
Member

@iandol @samuela I think ideally the docs would handle either/both and also if neither/none is installed.

@maxim-belkin
Copy link
Member

maxim-belkin commented Jan 25, 2019

One should source only one file:

$(brew --prefix)/etc/profile.d/bash_completion.sh

This file checks that Bash has the right version and then sources the right bash_completion file. In case you have bash-completion formula installed, it will source

/usr/local/Cellar/bash-completion/1.3_3/etc/bash_completion

If you have bash-completion@2 installed, it will source

/usr/local/Cellar/bash-completion@2/2.8/share/bash-completion/bash_completion

This bash_completion file provides some Bash-specific completions and also loads all the right program-specific completions.

@iandol
Copy link
Contributor

iandol commented Jan 25, 2019

But why does @samuela not even have a bash_completion.d/ on his system, as the completions files include brew and brew-services so I would have imagined they'd be present on all homebrew installs whether bash-completion was installed or not?

As for the docs, I wonder if the else ... echo "run: brew install git bash-completion" should be removed — as it only talks about Homebrew’s completions which is IINM not related to the bash-completion project.

While we're here, why does it recommend to use: if type brew 2&>/dev/null; then — why not just look for the folder directly?

@iandol
Copy link
Contributor

iandol commented Jan 25, 2019

@maxim-belkin thanks for your knowledge. However I don't have that file:

 ❯ ll $(brew --prefix)/etc/profile.d/bash_completion.sh
ls: /usr/local/etc/profile.d/bash_completion.sh: No such file or directory

@maxim-belkin
Copy link
Member

maxim-belkin commented Jan 25, 2019

bash-completion and bash-completion@2 store program-specific programmable completions in different folders (this is what I have on my Mac):

$ brew list bash-completion
/usr/local/Cellar/bash-completion/1.3_3/etc/bash_completion.d/ (180 files)
/usr/local/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh
/usr/local/Cellar/bash-completion/1.3_3/etc/bash_completion

$ brew list bash-completion@2
/usr/local/Cellar/bash-completion@2/2.8/etc/profile.d/bash_completion2.sh
/usr/local/Cellar/bash-completion@2/2.8/share/bash-completion/ (657 files)
/usr/local/Cellar/bash-completion@2/2.8/share/cmake/ (2 files)
/usr/local/Cellar/bash-completion@2/2.8/share/pkgconfig/bash-completion.pc

@iandol what does brew list bash-completion or brew list bash-completion@2 return to you?

@iandol
Copy link
Contributor

iandol commented Jan 25, 2019

I have neither of them installed on my macOS system; I only have the default auto-installed completion files.

@maxim-belkin
Copy link
Member

Then you shouldn't be surprised that you don't have $(brew --prefix)/etc/profile.d/bash_completion.sh

@MikeMcQuaid
Copy link
Member

@maxim-belkin Please note what I wrote above:

I think ideally the docs would handle either/both and also if neither/none is installed.

Would be good to have something that handles bash-completion being installed or just bash_completion files being installed by formulae.

@maxim-belkin
Copy link
Member

Would be good to have something that handles bash-completion being installed or just bash_completion files being installed by formulae.

Currently, the situation is as follows:

  1. $(brew --prefix)/etc/bash_completion.d/ is used by:
    - brew
    - completions installed by individual formulae
    - bash-completion formula
  2. bash-completion@2 formula installs its completion files in #{share}/bash-completion/

Both bash-completion and bash-completion@2 formulae provide special scripts that safe-guard against sourcing their completions under wrong Bash version.

Our options

  1. Change bash-completion@2 formula to install its completions in $(brew --prefix)/etc/bash_completion.d/ and instruct users to blindly source all files in that directory. In that case we don't care about those special scripts that bash-completion and bash-completion@2 formula provide.

  2. Don't change installation locations anywhere but make sure users understand that programmable completions installed by bash-completion formula will be sourced automatically if they source all files in $(brew --prefix)/etc/bash_completion.d/

  3. Change bash-completions formula to install its completions in a different folder. In this case users will have to

    • source all files in $(brew --prefix)/etc/bash_completion.d/ (Brew + individual formulae-provided bash completions)
    • source one more script provided by either of the bash-completion* formulae

@samuela
Copy link
Contributor Author

samuela commented Jan 25, 2019

But why does @samuela not even have a bash_completion.d/ on his system, as the completions files include brew and brew-services so I would have imagined they'd be present on all homebrew installs whether bash-completion was installed or not?

I do in fact have that directory on my system. I think bash was complaining because that directory has no file named "*".

@maxim-belkin
Copy link
Member

Bash translates * to a literal symbol * only when the directory is completely empty (0 non-hidden files/directories).

Brew installs its own completions in $(brew --prefix)/etc/bash_completion.d/, so this directory must exist. There might be something wrong with your setup. A quick-and-dirty fix would be to manually add a symbolic link to brew completions in there:

cd $(brew --prefix)/etc/profile.d/
ln -s ../../Homebrew/completions/bash/brew

@MikeMcQuaid
Copy link
Member

@maxim-belkin Could you suggest a version that will work for the docs even if none of these files or directories exist?

@maxim-belkin
Copy link
Member

sure...

@MikeMcQuaid
Copy link
Member

I've opened #5625 to improve these instructions. Let me know what you all think.

@maxim-belkin
Copy link
Member

maxim-belkin commented Jan 27, 2019 via email

@MikeMcQuaid
Copy link
Member

Great, thanks @maxim-belkin.

@iandol
Copy link
Contributor

iandol commented Jan 28, 2019

@MikeMcQuaid — if we think @samuela's empty folder is not a totally isolated incident, is it worth to also check the directory is not empty, something like [ -z "$(ls -A $(brew --prefix)/etc/bash_completion.d)" ] — or is this overkill for an isolated incident?

@MikeMcQuaid
Copy link
Member

@iandol Can we move discussion to #5625, it's hard to keep track of both place.

@lock lock bot added the outdated PR was locked due to age label Feb 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

No branches or pull requests

4 participants