From a62e88304b3857267d510d3066218715fdffa106 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 30 Nov 2021 22:12:22 +0800 Subject: [PATCH] shellenv: check that Homebrew's prefix precedes `/usr/bin` Some setups (e.g. a default `tmux` session) will result in a user starting multiple nested login shells. This is a problem for the way we currently handle `shellenv` because a login shell invokes `/usr/libexec/path_helper` which will prepend the contents of `/etc/paths` and `/etc/paths.d` to `PATH`. In particular, the second login shell will place `brew` further down the `PATH` than desired in a non-`/usr/local` prefix, since `brew shellenv` will no longer produce output the second time around. Let's fix this by replacing the check that `brew` is in `PATH` with a check that `${HOMEBREW_PREFIX}/bin` precedes `/usr/bin` in `PATH`. Fixes #11851, #11883, Homebrew/discussions#2547. See also: - Homebrew/discussions#2237 - https://superuser.com/questions/544989/does-tmux-sort-the-path-variable --- Library/Homebrew/cmd/shellenv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index 5c27621515..d7678d56ee 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -11,7 +11,7 @@ # shellcheck disable=SC2154 homebrew-shellenv() { if [[ "${HOMEBREW_SHELLENV_PREFIX}" == "${HOMEBREW_PREFIX}" ]] && - [[ "$(PATH="${HOMEBREW_PATH}" command -v brew)" == "${HOMEBREW_PREFIX}/bin/brew" ]] + [[ "${HOMEBREW_PATH%%/usr/bin:*}" == *"${HOMEBREW_PREFIX}/bin"* ]] then return fi