From c1666676667d474986aa4fcb8b4a72b5cdc828da Mon Sep 17 00:00:00 2001 From: Adrian Ho Date: Sat, 11 Jul 2020 22:28:27 +0800 Subject: [PATCH] shellenv: Fix shell detection It currently switches on `$SHELL`, which points to the user's login shell. However, `shellenv` may be used in contexts where the running shell isn't `$SHELL` (e.g. csh-based `cron` scripts), and Linux desktop environments may set up user sessions in ways that trip up the current algorithm (see #7965 for an example). To work correctly in all circumstances and environments, its output should be determined by the context (calling shell) instead. Fixes #7965. --- Library/Homebrew/cmd/shellenv.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index 04d8121daf..257fec7e8e 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -6,8 +6,8 @@ #: Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`) with: `eval $(brew shellenv)` homebrew-shellenv() { - case "$SHELL" in - */fish|fish) + case "$(/bin/ps -p $PPID -o comm=)" in + fish|-fish) echo "set -gx HOMEBREW_PREFIX \"$HOMEBREW_PREFIX\";" echo "set -gx HOMEBREW_CELLAR \"$HOMEBREW_CELLAR\";" echo "set -gx HOMEBREW_REPOSITORY \"$HOMEBREW_REPOSITORY\";" @@ -15,7 +15,7 @@ homebrew-shellenv() { echo "set -q MANPATH; or set MANPATH ''; set -gx MANPATH \"$HOMEBREW_PREFIX/share/man\" \$MANPATH;" echo "set -q INFOPATH; or set INFOPATH ''; set -gx INFOPATH \"$HOMEBREW_PREFIX/share/info\" \$INFOPATH;" ;; - */csh|csh|*/tcsh|tcsh) + csh|-csh|tcsh|-tcsh) echo "setenv HOMEBREW_PREFIX $HOMEBREW_PREFIX;" echo "setenv HOMEBREW_CELLAR $HOMEBREW_CELLAR;" echo "setenv HOMEBREW_REPOSITORY $HOMEBREW_REPOSITORY;"