From f7b8681bc95db17bea12ff7d12c179d57b890246 Mon Sep 17 00:00:00 2001 From: Conlan Cesar Date: Mon, 7 Oct 2024 14:11:02 -0400 Subject: [PATCH 1/3] Add zsh site-functions to `fpath` I considered doing a fallthough in the case-statement, but that doesn't work on bash leq 4 (notably, those versions shipped with MacOS by default). I chose to prepend the value to the array to mirror the homebrew completion [instructions page](https://docs.brew.sh/Shell-Completion). I also chose to leave off the `-d`irectory check -- zsh seems to tolerate invalid paths, so there isn't much harm in adding it anyway. I'm flexible on any of these choices should someone feel strongly. However, I imagine this is the best combination given the trade-offs we have. --- Library/Homebrew/cmd/shellenv.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index 8634b65dafa08..498510ac44442 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -81,6 +81,10 @@ homebrew-shellenv() { echo "export HOMEBREW_PREFIX=\"${HOMEBREW_PREFIX}\";" echo "export HOMEBREW_CELLAR=\"${HOMEBREW_CELLAR}\";" echo "export HOMEBREW_REPOSITORY=\"${HOMEBREW_REPOSITORY}\";" + if [[ "${HOMEBREW_SHELL_NAME}" == "zsh" ]] || [[ "${HOMEBREW_SHELL_NAME}" == "-zsh" ]] + then + echo "fpath[1,0]=\"${HOMEBREW_PREFIX}/share/zsh/site-functions\";" + fi if [[ -n "${PATH_HELPER_ROOT}" ]] then PATH_HELPER_ROOT="${PATH_HELPER_ROOT}" PATH="${HOMEBREW_PATH}" /usr/libexec/path_helper -s From aea87757ff9aa6b304eaa7eef8916d3e85bd5c9e Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Tue, 15 Oct 2024 00:01:17 +0800 Subject: [PATCH 2/3] docs/Shell-Completion: update docs for Zsh completions --- docs/Shell-Completion.md | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/Shell-Completion.md b/docs/Shell-Completion.md index 69f1e8e55aece..d8a145e310168 100644 --- a/docs/Shell-Completion.md +++ b/docs/Shell-Completion.md @@ -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`: From 94426ba18b8ecaacaa3ae308b7578c9832401431 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Tue, 15 Oct 2024 00:36:54 +0800 Subject: [PATCH 3/3] docs/Shell-Completion: update Zsh completions docs for Linux --- docs/Shell-Completion.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Shell-Completion.md b/docs/Shell-Completion.md index d8a145e310168..2f0ee2bd5dbd8 100644 --- a/docs/Shell-Completion.md +++ b/docs/Shell-Completion.md @@ -34,14 +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`, 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: +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, `eval "$(brew shellenv)"` should be in your `~/.zprofile` (on macOS) or `~/.zshrc` (on Linux). All you need is add the following to your `~/.zshrc` if it's not already there, and, if you're on Linux, make sure it's placed after `eval "$(brew shellenv)"`: ```sh autoload -Uz compinit compinit ``` -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. +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, make sure `eval "$(brew shellenv)"` is called before sourcing `oh-my-zsh.sh` if you're on Linux, and you should be all set without any additional configuration. You may also need to forcibly rebuild `zcompdump`: