speedup bash completion loading suggestion in docs

The current suggestion for users shells out to `brew --prefix` three separate times, which has a non-zero overhead (as per quick benchmark below, approx 20ms per invocation). By making a minor change, the first invocation can be stored in a local variable to reduce shell startup time.

```
$ hyperfine --warmup=3 'brew --prefix'       
Benchmark #1: brew --prefix
  Time (mean ± σ):      21.3 ms ±   1.5 ms    [User: 8.8 ms, System: 10.6 ms]
  Range (min … max):    20.3 ms …  37.0 ms    128 runs
```
This commit is contained in:
Matthew Rothenberg 2019-05-07 12:36:02 -04:00 committed by GitHub
parent 84085bd430
commit dc30e9f64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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