b86a99da177ad40de2906582c65a3d9f53b73c60

Author
Ininsico <157946121+Ininsico@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(brew): add sbin to PATH (#13780)

Diff

 1diff --git a/plugins/brew/README.md b/plugins/brew/README.md
 2index 07c38738099a9a3e1d5ee53a62e3e86ea650f5ef..5e3e3fab68687f4fb57a12bd4cb2c1ee1d7abc63 100644
 3--- a/plugins/brew/README.md
 4+++ b/plugins/brew/README.md
 5@@ -17,6 +17,12 @@ If `brew` is not found in the PATH, this plugin will attempt to find it in commo
 6 In case you installed `brew` in a non-common location, you can still set `BREW_LOCATION` variable pointing to
 7 the `brew` binary before sourcing `oh-my-zsh.sh` and it'll set up the environment.
 8 
 9+### sbin directory
10+
11+This plugin also adds `$HOMEBREW_PREFIX/sbin` to the PATH if the directory exists and isn't already present.
12+Some Homebrew formulae (e.g. `mtr`) install executables to `sbin`, which `brew doctor` checks for. This
13+ensures the `bdr` alias runs without warnings.
14+
15 ## Aliases
16 
17 | Alias    | Command                                 | Description                                                           |
18diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh
19index 7d5db206816e4b8ab4df1716df7cc6f3ae552483..45cd89f44a3741c5382dceb070a405239af495ea 100644
20--- a/plugins/brew/brew.plugin.zsh
21+++ b/plugins/brew/brew.plugin.zsh
22@@ -30,6 +30,16 @@ if [[ -z "$HOMEBREW_PREFIX" ]]; then
23   export HOMEBREW_PREFIX="$(brew --prefix)"
24 fi
25 
26+# Add Homebrew sbin to PATH if it exists and is not already in PATH.
27+# Homebrew's shellenv only adds bin directories, not sbin. Some formulae
28+# (e.g. mtr) install executables to sbin, and brew doctor warns if it's
29+# missing from PATH.
30+if [[ -d "$HOMEBREW_PREFIX/sbin" ]]; then
31+  if [[ ! "$PATH" == *"$HOMEBREW_PREFIX/sbin"* ]]; then
32+    export PATH="$HOMEBREW_PREFIX/sbin:$PATH"
33+  fi
34+fi
35+
36 if [[ -d "$HOMEBREW_PREFIX/share/zsh/site-functions" ]]; then
37   fpath+=("$HOMEBREW_PREFIX/share/zsh/site-functions")
38 fi