shellenv.sh / fish shell: Move Brew PATHs to front if they exist (add -m arg to fish_add_path) #18304
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.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?(Unchecked steps aren't applicable here, in my opinion)
This PR addresses an issue when a PATH variable with Homebrew paths is inherited, modified, and then
brew shellenv
is evaluated again. In this case, the expected behavior is that Homebrew directories should be placed at the front of the PATH. However, since-m
(move component) isn’t specified,fish_add_path
doesn’t modify the variable, this can, for example, cause binaries in/usr/bin
(like XCode CLI tools' Python) to take precedence.I encountered this in VSCode, where
eval (/opt/homebrew/bin/brew shellenv fish)
in myconfig.fish
didn’t properly update the PATH, as VSCode's environment resolution already included the paths,just not at the top. This change ensures$HOMEBREW_PREFIX/bin
and$HOMEBREW_PREFIX/sbin
are always placed first inPATH
.Correction:
It's not actually VSCode's fault that the Brew PATH components aren't at the top, they are, but when
fish
thinks it's a login shell (which it does when run in VSCode's terminal), it will add some PATH components before the inherited ones, causing the issue. Nonetheless, based on the behavior for other shells, it seems like the behavior with-m
specified, which is what this PR does, would be what is intended forbrew shellenv
.