New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/shellenv.sh: make brew shellenv
idempotent
#11789
Conversation
999bca3
to
569672e
Compare
I wonder if it's worth emitting a warning when |
Then it will raise a warning when the user create a subshell or source the shell profile manually. Maybe variable
Besides, for Linux users with a desktop environment, the file |
Ok, let's skip the warning then. I have another question: what are the advantages of this approach over, say, making the output of |
Only check whether Here is my first implementation (d0ff10b). It checks the occurrences of brew's entries in |
Yes. That's what the "etc" stood for. Thanks for the update; I'll have a look shortly. |
The implementation is way simpler. Checking whether something is in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. The only case I can imagine it might have issues is if you're intentionally running /opt/homebrew/bin/brew shellenv
and /usr/local/bin/brew shellenv
. I wonder if HOMEBREW_SHELLENV_SET
could be something like HOMEBREW_SHELLENV_PREFIX=$HOMEBREW_PREFIX
and then do a comparison to check the values match?
Happy to merge this as-is, though.
Library/Homebrew/cmd/shellenv.sh
Outdated
;; | ||
*) | ||
echo "export HOMEBREW_PREFIX=\"${HOMEBREW_PREFIX}\";" | ||
echo "export HOMEBREW_CELLAR=\"${HOMEBREW_CELLAR}\";" | ||
echo "export HOMEBREW_REPOSITORY=\"${HOMEBREW_REPOSITORY}\";" | ||
[[ ":${HOMEBREW_SHELLENV_SET}:" == *":${HOMEBREW_PREFIX}:"* ]] && return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May as well move this above the HOMEBREW_PREFIX
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a new variable HOMEBREW_SHELLENV_PREFIX
to make sure the current Homebrew is initialized correctly.
eval "(/opt/homebrew/bin/brew shellenv)" # add `/opt/homebrew/bin` to `PATH` and set `MANPATH`, `INFOPATH`
eval "(/opt/homebrew/bin/brew shellenv)" # no effect
eval "(/opt/homebrew/bin/brew shellenv)" # no effect
eval "(/usr/local/bin/brew shellenv)" # add `/opt/local/bin` to `PATH` and set `MANPATH`, `INFOPATH`
eval "(/usr/local/bin/brew shellenv)" # no effect
eval "(/usr/local/bin/brew shellenv)" # no effect
eval "(/opt/homebrew/bin/brew shellenv)" # add `/opt/homebrew/bin` to `PATH` and set `MANPATH`, `INFOPATH`
eval "(/usr/local/bin/brew shellenv)" # add `/opt/local/bin` to `PATH` and set `MANPATH`, `INFOPATH`
eval "(/opt/homebrew/bin/brew shellenv)" # add `/opt/homebrew/bin` to `PATH` at the front (but it is duplicate)
eval "(/usr/local/bin/brew shellenv)" # add `/opt/local/bin` to `PATH` at the front (but it is duplicate)
Or may only keep HOMEBREW_SHELLENV_PREFIX
and remove HOMEBREW_SHELLENV_SET
to keep duplicate entries in MANPATH
and INFOPATH
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far!
Great work here, thanks again @XuehaiPan! |
I am sorry that this PR causes inconsistent shell behavior by introducing a new variable after You can replace
to always get all export statements for Homebrew entries. |
Do we want to reconsider the answers to either of my two questions/suggestions above? I think doing either of them might help resolve some of the issues people are having. For clarity, I'm referring to
and
|
I have created a new PR #11930 for that the variable The warning should only arise on the |
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Make
brew shellenv
idempotent. This implementation simply a new environment variableHOMEBREW_SHELLENV_SET
to avoid duplicate initialization.I make
HOMEBREW_SHELLENV_SET
a colon separated list of brew prefixes rather than a constant to handle multi-instance of brew installation.It has several limitations, but I think it doesn't matter. For example, it can not handle file redirection (
[ ! -t 1 ]
can not work):Resolves Homebrew/install#559.