docs/Shell-Completion: update docs for Zsh completions

This commit is contained in:
Ruoyu Zhong 2024-10-15 00:01:17 +08:00
parent f7b8681bc9
commit aea87757ff
No known key found for this signature in database

View File

@ -34,23 +34,14 @@ If you are using Homebrew's `bash` as your shell (i.e. `bash` >= v4) you should
## Configuring Completions in `zsh`
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`:
To make Homebrew's completions available in `zsh`, the Homebrew-managed `zsh/site-functions` path needs to be inserted into `FPATH` before initialising `zsh`'s completion facility. This is done by `brew shellenv`, so if you followed the post-Homebrew installation steps and have `eval "$(brew shellenv)"` in your `~/.zprofile`, all you need is add the following to your `~/.zshrc` if it's not already there:
```sh
if type brew &>/dev/null
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
autoload -Uz compinit
compinit
fi
autoload -Uz compinit
compinit
```
This must be done before `compinit` is called. Note that if you are using Oh My Zsh, it will call `compinit` for you when you source `oh-my-zsh.sh`. In this case, instead of the above, add the following line to your `~/.zshrc`, before you source `oh-my-zsh.sh`:
```sh
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
```
Note that if you are using Oh My Zsh, it will call `compinit` for you when you source `oh-my-zsh.sh`. In this case, you should be all set without any additional configuration.
You may also need to forcibly rebuild `zcompdump`: