bash completion should not call brew if brew doesn't exist

In the section "Configuring Completions in `bash`", there's a line of code that sets `HOMEBREW_PREFIX` by calling `brew --prefix`, but it's done before calling `type brew` to see if brew exists.  This gives a "-bash: brew: command not found" if you don't have brew installed. That line should be moved inside the `if`.
This commit is contained in:
Andy Lester 2019-10-02 09:00:23 -05:00 committed by GitHub
parent 6c2b9ffdc1
commit c296c5f2d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,8 +11,8 @@ You must configure your shell to enable its completion support. This is because
To make Homebrew's completions available in `bash`, you must source the definitions as part of your shell's startup. Add the following to your `~/.bash_profile` file: To make Homebrew's completions available in `bash`, you must source the definitions as part of your shell's startup. Add the following to your `~/.bash_profile` file:
```sh ```sh
HOMEBREW_PREFIX=$(brew --prefix)
if type brew &>/dev/null; then if type brew &>/dev/null; then
HOMEBREW_PREFIX=$(brew --prefix)
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else else