shellenv: emit zsh fpath in nested/child shells#21884
Open
sumanthratna wants to merge 10 commits intoHomebrew:mainfrom
Open
shellenv: emit zsh fpath in nested/child shells#21884sumanthratna wants to merge 10 commits intoHomebrew:mainfrom
sumanthratna wants to merge 10 commits intoHomebrew:mainfrom
Conversation
The early-return idempotency check skipped all output when PATH already contained Homebrew's bin/sbin. Unlike PATH, zsh's fpath is a shell-local array not inherited by child processes, so completions broke in tmux/zellij panes and nested zsh shells. Move shell detection before the early return and always emit the fpath line for zsh. Fixes Homebrew#21879
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes brew shellenv for zsh in nested/child shells by ensuring the zsh fpath initialization is still emitted even when the PATH idempotency/early-return condition is met (so zsh completions work in tmux/zellij panes and nested zsh sessions).
Changes:
- Move shell detection ahead of the PATH-based early return in
shellenv.sh. - When early return triggers, still emit the
fpath[1,0]=...line for zsh. - Add an integration spec asserting
fpathoutput forbrew shellenv zsheven when PATH already contains the Homebrew prefix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Library/Homebrew/cmd/shellenv.sh | Reorders early-return logic and ensures zsh fpath is emitted in the idempotent PATH case. |
| Library/Homebrew/test/cmd/shellenv_spec.rb | Adds an integration test covering the zsh fpath output when PATH already includes Homebrew. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The unconditional fpath[1,0]= caused duplicate entries when
brew shellenv zsh was evaluated from both .zprofile and .zshrc
in the same login shell. Use zsh's ${fpath[(Ie)...]} exact-match
lookup so the directory is only prepended when not already present.
Deduplicate Homebrew's zsh site-functions entry while always moving it to the front of fpath. This keeps repeated `brew shellenv zsh` evals returning success and preserves Homebrew's completion precedence. Add a regression test for the pre-existing non-first fpath case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The early-return idempotency check skipped all output when PATH already contained Homebrew's bin/sbin. Unlike PATH, zsh's fpath is a shell-local array not inherited by child processes, so completions broke in tmux/zellij panes and nested zsh shells.
Move shell detection before the early return and always emit the fpath line for zsh.
Fixes #21879
brew lgtm(style, typechecking and tests) with your changes locally?brew lgtmcomplains about unrelated typechecking configbrew shellenv zshwithPATHset to trigger the early return — confirmed it now emits thefpath[1,0]=line (previously produced zero output)brew shellenv bashwith the samePATH— confirmed it still produces no output on early return (no regression)brew style,brew typecheck, andbrew tests --only=cmd/shellenv— all pass