Update Shell-Completion.md

This commit is contained in:
EricFromCanada 2021-11-17 14:27:15 -05:00
parent cb9db80157
commit b71644e735
No known key found for this signature in database
GPG Key ID: 179D9CDDDB814168

View File

@ -4,7 +4,7 @@ Homebrew comes with completion definitions for the `brew` command. Some packages
`zsh`, `bash` and `fish` are currently supported. `zsh`, `bash` and `fish` are currently supported.
You must then configure your shell to enable its completion support. This is because the Homebrew-managed completions are stored under `HOMEBREW_PREFIX` which your system shell may not be aware of, and since it is difficult to automatically configure `bash` and `zsh` completions in a robust manner, the Homebrew installer does not do it for you. You must manually configure your shell to enable its completion support. This is because the Homebrew-managed completions are stored under `HOMEBREW_PREFIX` which your system shell may not be aware of, and since it is difficult to automatically configure `bash` and `zsh` completions in a robust manner, the Homebrew installer does not do it for you.
Shell completions for external Homebrew commands are not automatically installed. To opt-in to using completions for external commands (if provided), they need to be linked to `HOMEBREW_PREFIX` by running `brew completions link`. Shell completions for external Homebrew commands are not automatically installed. To opt-in to using completions for external commands (if provided), they need to be linked to `HOMEBREW_PREFIX` by running `brew completions link`.
@ -28,13 +28,13 @@ then
fi fi
``` ```
If you install the `bash-completion` formula, this will automatically source the completions' initialisation script (so you do not need to follow the instructions in the caveats). If you install the `bash-completion` formula, this will automatically source the completions' initialisation script (so you do not need to follow the instructions in the formula's caveats).
If you are using the `bash` formula as your shell (i.e. `bash` >= v4) you should use the `bash-completion@2` formula instead. If you are using Homebrew's `bash` as your shell (i.e. `bash` >= v4) you should use the `bash-completion@2` formula instead.
## Configuring Completions in `zsh` ## Configuring Completions in `zsh`
To make Homebrew's completions available in `zsh`, you must get the Homebrew-managed zsh site-functions on your `FPATH` before initialising `zsh`'s completion facility. Add the following to your `~/.zshrc` file: To make Homebrew's completions available in `zsh`, you must insert the Homebrew-managed `zsh/site-functions` path into your `FPATH` before initialising `zsh`'s completion facility. Add the following to your `~/.zshrc`:
```sh ```sh
if type brew &>/dev/null if type brew &>/dev/null
@ -55,13 +55,13 @@ FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
You may also need to forcibly rebuild `zcompdump`: You may also need to forcibly rebuild `zcompdump`:
```sh ```sh
rm -f ~/.zcompdump; compinit rm -f ~/.zcompdump; compinit
``` ```
Additionally, if you receive "zsh compinit: insecure directories" warnings when attempting to load these completions, you may need to run this: Additionally, if you receive "zsh compinit: insecure directories" warnings when attempting to load these completions, you may need to run this:
```sh ```sh
chmod -R go-w "$(brew --prefix)/share" chmod -R go-w "$(brew --prefix)/share"
``` ```
## Configuring Completions in `fish` ## Configuring Completions in `fish`