Skip to content
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

eval "$(/usr/bin/env brew shellenv)" causes duplicate path, man path, info path #17142

Closed
2 of 3 tasks
bnse opened this issue Apr 24, 2024 · 4 comments
Closed
2 of 3 tasks
Labels
bug Reproducible Homebrew/brew bug

Comments

@bnse
Copy link

bnse commented Apr 24, 2024

brew doctor output

➜ brew doctor
Your system is ready to brew.

Verification

  • My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update twice and am still able to reproduce my issue.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

➜ brew config
HOMEBREW_VERSION: 4.2.19-63-g0612657
ORIGIN: https://github.com/Homebrew/brew
HEAD: 06126572b3c1173428768377669b42fcaee90845
Last commit: 11 hours ago
Core tap JSON: 24 Apr 04:09 UTC
Core cask tap JSON: 24 Apr 04:09 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: lvim
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_NO_AUTO_UPDATE: set
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.1.4 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: quad-core 64-bit kabylake
Clang: 15.0.0 build 1500
Git: 2.44.0 => /usr/local/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 14.4.1-x86_64
CLT: 15.3.0.0.1.1708646388
Xcode: 15.3

What were you trying to do (and why)?

echo $PATH | awk -F":" '{ for (i=4; i<=NF; i++) print $i }'|grep -i "^/usr/local/bin"|uniq -c
   2 /usr/local/bin

What happened (include all command output)?

echo $MANPATH
/usr/local/share/man:/usr/share/man:/usr/local/share/man:/Applications/kitty.app/Contents/Resources/man::

~echo $INFOPATH
/usr/local/share/info:

at the end, found the

/man::

/info:

What did you expect to happen?

suggestion

Delete PATH, MANPATH, and INFOPATH in the default shellenv.sh.

brew should only handle its own private variables, such as HOMEBREW_PREFIX,

This way we can use external functions to handle these environment variables.
For example, avoid duplication or sequencing.

# is_homebrew_prefix_set && from_the_homebrew_prefix_add_you_want
[[ ! -z "$HOMEBREW_PREFIX" ]] && addTOPATH "$HOMEBREW_PREFIX/bin"
# 🚀
eval "$(/usr/bin/env brew shellenv)" && [[ ! -z "$HOMEBREW_PREFIX" ]] && addToPATH "$HOMEBREW_PREFIX/bin"


function addToPATH() {
	case ":$PATH:" in
	*":$1:"*) : ;;        # already there
	*) PATH="$1:$PATH" ;; # or PATH="$PATH:$1"
	esac
}
function addToMANPATH() {
	case ":$MANPATH:" in
	*":$1:"*) : ;;              # already there
	*) MANPATH="$1:$MANPATH" ;; # or MANPATH="$MANPATH:$1"
	esac
}
function addToINFOPATH() {
	case ":$INFOPATH:" in
	*":$1:"*) : ;;                # already there
	*) INFOPATH="$1:$INFOPATH" ;; # or INFOPATH="$INFOPATH:$1"
	esac
}
_brewEnv() {
	# eval "$(/usr/bin/env brew shellenv)" ## remove it from ~/.bashrc
	if command_exists brew; then

		local _homebrew_prefix="$(dirname $(dirname $(which brew)))"
		export HOMEBREW_PREFIX="$_homebrew_prefix"
		export HOMEBREW_CELLAR="$_homebrew_prefix/Cellar"
		export HOMEBREW_REPOSITORY="$_homebrew_prefix/Homebrew"

		local _homebrew_prefix_bin="$_homebrew_prefix/bin"
		local _homebrew_prefix_sbin="$_homebrew_prefix/sbin"

		addToPATH "$_homebrew_prefix_bin"
		addToPATH "$_homebrew_prefix_sbin"

		addToMANPATH "$_homebrew_prefix/share/man"
		# addToINFOPATH "$_homebrew_prefix/share/info" ## info command has removed on macOS

		export HOMEBREW_NO_AUTO_UPDATE=1
	fi
}
_brewEnv
echo $PATH | awk -F":" '{ for (i=4; i<=NF; i++) print $i }'|grep -i "^/usr/local/bin"|uniq -c
   1 /usr/local/bin

Step-by-step reproduction instructions (by running brew commands)

no more.
@bnse bnse added the bug Reproducible Homebrew/brew bug label Apr 24, 2024
@MikeMcQuaid
Copy link
Member

Delete PATH, MANPATH, and INFOPATH in the default shellenv.sh.

brew should only handle its own private variables, such as HOMEBREW_PREFIX,

This is not going to happen. It will break the setup for everyone who relies on this.

For example, avoid duplication or sequencing.

We intentionally are willing to accept duplication here (it does no harm) to ensure that the sequencing is correct (so that bin/brew and brew installed bins and sbins are at the front of the various *PATH.

@bnse
Copy link
Author

bnse commented Apr 24, 2024

This is not going to happen. It will break the setup for everyone who relies on this.

I think good design should be able to separate private and public parts.

brew_env() {
  set_brew_private_env
  set_public_env
}

Equal:

set_brew_private_env && set_public_env

This makes it easier to combine other programs. And can be called multiple times safely.

set_brew_private_env && set_brew_public_env
set_brew_public_env && more_process_a
set_brew_private_env && more_process_b

We intentionally are willing to accept duplication here (it does no harm) to ensure that the sequencing is correct (so that bin/brew and brew installed bins and sbins are at the front of the various *PATH.

We got a clean path handling.

PATH = user_path:brew_path:sys_path

OR

clean_path_handle() {
  addToPath user_path
  addToPath brew_path
  addToPath sys_path
}

@MikeMcQuaid
Copy link
Member

I think good design should be able to separate private and public parts.

I think the design is good already. Regardless: we cannot make backwards incompatible changes, like you're proposing.

@carlocab
Copy link
Member

brew shellenv is designed to work for 95% of our users. In its current form, it does that.

I don't think there is a way to make the changes you propose without either a) breaking shellenv for a significant proportion of the 95%, or b) making the code significantly more complex than it's worth making shellenv more useful to another 2-3% of users.

For your use case, I suggest sticking with the code you've already written to add Homebrew to PATH, MANPATH, etc instead of using shellenv.

However, if in fact there is a simple way to update shellenv without breaking it for any existing users, please open a pull request instead.

@carlocab carlocab closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/brew bug
Projects
None yet
Development

No branches or pull requests

3 participants