diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index c72d8fc8a3..0c476c25b1 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -81,7 +81,7 @@ case "$*" in ;; shellenv) source "${HOMEBREW_LIBRARY}/Homebrew/cmd/shellenv.sh" - homebrew-shellenv + homebrew-shellenv "$1" exit 0 ;; formulae) diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index a19a2223d5..2f2af3ff1f 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -1,4 +1,4 @@ -#: * `shellenv` +#: * `shellenv [bash|csh|fish|pwsh|sh|tcsh|zsh]` #: #: Print export statements. When run in a shell, this installation of Homebrew will be added to your `PATH`, `MANPATH`, and `INFOPATH`. #: @@ -6,6 +6,8 @@ #: To help guarantee idempotence, this command produces no output when Homebrew's `bin` and `sbin` directories are first and second #: respectively in your `PATH`. Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, #: `~/.bash_profile`, or `~/.zprofile`) with: `eval "$(brew shellenv)"` +#: +#: The shell can be specified explicitly with a supported shell name parameter. Unknown shells will output POSIX exports. # HOMEBREW_CELLAR and HOMEBREW_PREFIX are set by extend/ENV/super.rb # HOMEBREW_REPOSITORY is set by bin/brew @@ -18,7 +20,14 @@ homebrew-shellenv() { return fi - case "$(/bin/ps -p "${PPID}" -c -o comm=)" in + if [[ -n "$1" ]] + then + HOMEBREW_SHELL_NAME="$1" + else + HOMEBREW_SHELL_NAME="$(/bin/ps -p "${PPID}" -c -o comm=)}" + fi + + case "${HOMEBREW_SHELL_NAME}" in fish | -fish) echo "set -gx HOMEBREW_PREFIX \"${HOMEBREW_PREFIX}\";" echo "set -gx HOMEBREW_CELLAR \"${HOMEBREW_CELLAR}\";"