Diff
1diff --git a/plugins/brew/README.md b/plugins/brew/README.md
2index 64e0e1153977eba1ad74464ae13ca1bc00448d4b..9ce2c5bb03700f4b57f079db4a57055e8bcc49b5 100644
3--- a/plugins/brew/README.md
4+++ b/plugins/brew/README.md
5@@ -10,7 +10,10 @@ plugins=(... brew)
6
7 ## Shellenv
8
9-This plugin also executes `brew shellenv` at plugin load to set up many useful variables, such as `HOMEBREW_PREFIX` or `HOMEBREW_REPOSITORY`.
10+If `brew` is not found in the PATH, this plugin will attempt to find it in common
11+locations, and execute `brew shellenv` to set the environment appropriately.
12+This plugin will also export `HOMEBREW_PREFIX="$(brew --prefix)"` if not previously
13+defined for convenience.
14
15 ## Aliases
16
17diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh
18index 4a2322216d8585f691306f8ffad2128dd6ff7480..41420b5b7047446eb4a360fcd03061ac662b7e49 100644
19--- a/plugins/brew/brew.plugin.zsh
20+++ b/plugins/brew/brew.plugin.zsh
21@@ -10,18 +10,21 @@ if (( ! $+commands[brew] )); then
22 else
23 return
24 fi
25+
26+ # Only add Homebrew installation to PATH, MANPATH, and INFOPATH if brew is
27+ # not already on the path, to prevent duplicate entries. This aligns with
28+ # the behavior of the brew installer.sh post-install steps.
29+ eval "$("$BREW_LOCATION" shellenv)"
30+ unset BREW_LOCATION
31 fi
32
33 if [[ -z "$HOMEBREW_PREFIX" ]]; then
34- if [[ -z $BREW_LOCATION ]]; then
35- eval "$(brew shellenv)"
36- else
37- eval "$("$BREW_LOCATION" shellenv)"
38- fi
39+ # Maintain compatability with potential custom user profiles, where we had
40+ # previously relied on always sourcing shellenv. OMZ plugins should not rely
41+ # on this to be defined due to out of order processing.
42+ export HOMEBREW_PREFIX="$(brew --prefix)"
43 fi
44
45-unset BREW_LOCATION
46-
47 alias bcubc='brew upgrade --cask && brew cleanup'
48 alias bcubo='brew update && brew outdated --cask'
49 alias brewp='brew pin'