diff --git a/Library/Homebrew/cmd/shellenv.sh b/Library/Homebrew/cmd/shellenv.sh index d7f2e73972..2434efee15 100644 --- a/Library/Homebrew/cmd/shellenv.sh +++ b/Library/Homebrew/cmd/shellenv.sh @@ -3,25 +3,30 @@ #: Print export statements. When run in a shell, this installation of Homebrew will be added to your `PATH`, `MANPATH`, and `INFOPATH`. #: #: The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times. +#: The variable `HOMEBREW_SHELLENV_PREFIX` will be exported to avoid adding duplicate entries to the environment variables. #: Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`) with: `eval $(brew shellenv)` # HOMEBREW_CELLAR and HOMEBREW_PREFIX are set by extend/ENV/super.rb # HOMEBREW_REPOSITORY is set by bin/brew # shellcheck disable=SC2154 homebrew-shellenv() { + [[ "${HOMEBREW_SHELLENV_PREFIX}" == "${HOMEBREW_PREFIX}" ]] && return + case "$(/bin/ps -p "${PPID}" -c -o comm=)" in - fish|-fish) + fish | -fish) echo "set -gx HOMEBREW_PREFIX \"${HOMEBREW_PREFIX}\";" echo "set -gx HOMEBREW_CELLAR \"${HOMEBREW_CELLAR}\";" echo "set -gx HOMEBREW_REPOSITORY \"${HOMEBREW_REPOSITORY}\";" + echo "set -gx HOMEBREW_SHELLENV_PREFIX \"${HOMEBREW_PREFIX}\";" echo "set -q PATH; or set PATH ''; set -gx PATH \"${HOMEBREW_PREFIX}/bin\" \"${HOMEBREW_PREFIX}/sbin\" \$PATH;" 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};" + echo "setenv HOMEBREW_SHELLENV_PREFIX ${HOMEBREW_PREFIX};" echo "setenv PATH ${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin:\$PATH;" echo "setenv MANPATH ${HOMEBREW_PREFIX}/share/man\`[ \${?MANPATH} == 1 ] && echo \":\${MANPATH}\"\`:;" echo "setenv INFOPATH ${HOMEBREW_PREFIX}/share/info\`[ \${?INFOPATH} == 1 ] && echo \":\${INFOPATH}\"\`;" @@ -30,6 +35,7 @@ homebrew-shellenv() { echo "export HOMEBREW_PREFIX=\"${HOMEBREW_PREFIX}\";" echo "export HOMEBREW_CELLAR=\"${HOMEBREW_CELLAR}\";" echo "export HOMEBREW_REPOSITORY=\"${HOMEBREW_REPOSITORY}\";" + echo "export HOMEBREW_SHELLENV_PREFIX=\"${HOMEBREW_PREFIX}\";" echo "export PATH=\"${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/sbin\${PATH+:\$PATH}\";" echo "export MANPATH=\"${HOMEBREW_PREFIX}/share/man\${MANPATH+:\$MANPATH}:\";" echo "export INFOPATH=\"${HOMEBREW_PREFIX}/share/info:\${INFOPATH:-}\";" diff --git a/docs/Manpage.md b/docs/Manpage.md index 339fbdbf15..e7a1775688 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -569,6 +569,7 @@ The search for *`text`* is extended online to `homebrew/core` and `homebrew/cask Print export statements. When run in a shell, this installation of Homebrew will be added to your `PATH`, `MANPATH`, and `INFOPATH`. The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times. +The variable `HOMEBREW_SHELLENV_PREFIX` will be exported to avoid adding duplicate entries to the environment variables. Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`) with: `eval $(brew shellenv)` ### `tap` [*`options`*] [*`user`*`/`*`repo`*] [*`URL`*] diff --git a/manpages/brew.1 b/manpages/brew.1 index a4e2cefcfc..a96152d4f1 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "July 2021" "Homebrew" "brew" +.TH "BREW" "1" "August 2021" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The Missing Package Manager for macOS (or Linux) @@ -792,7 +792,7 @@ Search for \fItext\fR in the given database\. Print export statements\. When run in a shell, this installation of Homebrew will be added to your \fBPATH\fR, \fBMANPATH\fR, and \fBINFOPATH\fR\. . .P -The variables \fBHOMEBREW_PREFIX\fR, \fBHOMEBREW_CELLAR\fR and \fBHOMEBREW_REPOSITORY\fR are also exported to avoid querying them multiple times\. Consider adding evaluation of this command\'s output to your dotfiles (e\.g\. \fB~/\.profile\fR, \fB~/\.bash_profile\fR, or \fB~/\.zprofile\fR) with: \fBeval $(brew shellenv)\fR +The variables \fBHOMEBREW_PREFIX\fR, \fBHOMEBREW_CELLAR\fR and \fBHOMEBREW_REPOSITORY\fR are also exported to avoid querying them multiple times\. The variable \fBHOMEBREW_SHELLENV_PREFIX\fR will be exported to avoid adding duplicate entries to the environment variables\. Consider adding evaluation of this command\'s output to your dotfiles (e\.g\. \fB~/\.profile\fR, \fB~/\.bash_profile\fR, or \fB~/\.zprofile\fR) with: \fBeval $(brew shellenv)\fR . .SS "\fBtap\fR [\fIoptions\fR] [\fIuser\fR\fB/\fR\fIrepo\fR] [\fIURL\fR]" Tap a formula repository\.