brew.plugin.zsh
3186 bytes
1if (( ! $+commands[brew] )); then
2 if [[ -n "$BREW_LOCATION" ]]; then
3 if [[ ! -x "$BREW_LOCATION" ]]; then
4 echo "[oh-my-zsh] $BREW_LOCATION is not executable"
5 return
6 fi
7 elif [[ -x /opt/homebrew/bin/brew ]]; then
8 BREW_LOCATION="/opt/homebrew/bin/brew"
9 elif [[ -x /usr/local/bin/brew ]]; then
10 BREW_LOCATION="/usr/local/bin/brew"
11 elif [[ -x /home/linuxbrew/.linuxbrew/bin/brew ]]; then
12 BREW_LOCATION="/home/linuxbrew/.linuxbrew/bin/brew"
13 elif [[ -x "$HOME/.linuxbrew/bin/brew" ]]; then
14 BREW_LOCATION="$HOME/.linuxbrew/bin/brew"
15 else
16 return
17 fi
18
19 # Only add Homebrew installation to PATH, MANPATH, and INFOPATH if brew is
20 # not already on the path, to prevent duplicate entries. This aligns with
21 # the behavior of the brew installer.sh post-install steps.
22 eval "$("$BREW_LOCATION" shellenv)"
23 unset BREW_LOCATION
24fi
25
26if [[ -z "$HOMEBREW_PREFIX" ]]; then
27 # Maintain compatibility with potential custom user profiles, where we had
28 # previously relied on always sourcing shellenv. OMZ plugins should not rely
29 # on this to be defined due to out of order processing.
30 export HOMEBREW_PREFIX="$(brew --prefix)"
31fi
32
33# Add Homebrew sbin to PATH if it exists and is not already in PATH.
34# Homebrew's shellenv only adds bin directories, not sbin. Some formulae
35# (e.g. mtr) install executables to sbin, and brew doctor warns if it's
36# missing from PATH.
37if [[ -d "$HOMEBREW_PREFIX/sbin" ]]; then
38 if [[ ! "$PATH" == *"$HOMEBREW_PREFIX/sbin"* ]]; then
39 export PATH="$HOMEBREW_PREFIX/sbin:$PATH"
40 fi
41fi
42
43if [[ -d "$HOMEBREW_PREFIX/share/zsh/site-functions" ]]; then
44 fpath+=("$HOMEBREW_PREFIX/share/zsh/site-functions")
45fi
46
47alias ba='brew autoremove'
48alias bcfg='brew config'
49alias bci='brew info --cask'
50alias bcin='brew install --cask'
51alias bcl='brew list --cask'
52alias bcn='brew cleanup'
53alias bco='brew outdated --cask'
54alias bcrin='brew reinstall --cask'
55alias bcubc='brew upgrade --cask && brew cleanup'
56alias bcubo='brew update && brew outdated --cask'
57alias bcup='brew upgrade --cask'
58alias bdr='brew doctor'
59alias bfu='brew upgrade --formula'
60alias bi='brew install'
61alias bih='brew install --HEAD'
62alias bl='brew list'
63alias bo='brew outdated'
64alias br='brew reinstall'
65alias brewp='brew pin'
66alias brewsp='brew list --pinned'
67alias brh='brew reinstall --HEAD'
68alias bs='brew search'
69alias bsl='brew services list'
70alias bsoff='brew services stop'
71alias bsoffa='bsoff --all'
72alias bson='brew services start'
73alias bsona='bson --all'
74alias bsr='brew services run'
75alias bsra='bsr --all'
76alias bu='brew update'
77alias bubo='brew update && brew outdated'
78alias bubu='bubo && bup'
79alias bubug='bubo && bugbc'
80alias bugbc='brew upgrade --greedy && brew cleanup'
81alias bup='brew upgrade'
82alias buz='brew uninstall --zap'
83
84function brews() {
85 local formulae="$(brew leaves | xargs brew deps --installed --for-each)"
86 local casks="$(brew list --cask 2>/dev/null)"
87
88 local blue="$(tput setaf 4)"
89 local bold="$(tput bold)"
90 local off="$(tput sgr0)"
91
92 echo "${blue}==>${off} ${bold}Formulae${off}"
93 echo "${formulae}" | sed "s/^\(.*\):\(.*\)$/\1${blue}\2${off}/"
94 echo "\n${blue}==>${off} ${bold}Casks${off}\n${casks}"
95}