Merge pull request #15363 from halostatue/shellenv-shell-parameter

Allow brew shellenv to accept a shell name param
This commit is contained in:
Mike McQuaid 2023-05-08 12:39:05 +01:00 committed by GitHub
commit 628626b078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -81,7 +81,7 @@ case "$*" in
;; ;;
shellenv) shellenv)
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/shellenv.sh" source "${HOMEBREW_LIBRARY}/Homebrew/cmd/shellenv.sh"
homebrew-shellenv homebrew-shellenv "$1"
exit 0 exit 0
;; ;;
formulae) formulae)

View File

@ -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`. #: 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 #: 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`, #: 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)"` #: `~/.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_CELLAR and HOMEBREW_PREFIX are set by extend/ENV/super.rb
# HOMEBREW_REPOSITORY is set by bin/brew # HOMEBREW_REPOSITORY is set by bin/brew
@ -18,7 +20,14 @@ homebrew-shellenv() {
return return
fi 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) fish | -fish)
echo "set -gx HOMEBREW_PREFIX \"${HOMEBREW_PREFIX}\";" echo "set -gx HOMEBREW_PREFIX \"${HOMEBREW_PREFIX}\";"
echo "set -gx HOMEBREW_CELLAR \"${HOMEBREW_CELLAR}\";" echo "set -gx HOMEBREW_CELLAR \"${HOMEBREW_CELLAR}\";"