summaryrefslogtreecommitdiff
path: root/oh-my-zsh/plugins/brew
diff options
context:
space:
mode:
Diffstat (limited to 'oh-my-zsh/plugins/brew')
-rw-r--r--oh-my-zsh/plugins/brew/README.md37
-rw-r--r--oh-my-zsh/plugins/brew/brew.plugin.zsh48
2 files changed, 85 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/brew/README.md b/oh-my-zsh/plugins/brew/README.md
new file mode 100644
index 0000000..9ce2c5b
--- /dev/null
+++ b/oh-my-zsh/plugins/brew/README.md
@@ -0,0 +1,37 @@
+# brew plugin
+
+The plugin adds several aliases for common [brew](https://brew.sh) commands.
+
+To use it, add `brew` to the plugins array of your zshrc file:
+
+```zsh
+plugins=(... brew)
+```
+
+## Shellenv
+
+If `brew` is not found in the PATH, this plugin will attempt to find it in common
+locations, and execute `brew shellenv` to set the environment appropriately.
+This plugin will also export `HOMEBREW_PREFIX="$(brew --prefix)"` if not previously
+defined for convenience.
+
+## Aliases
+
+| Alias | Command | Description |
+| -------- | ------------------------------------- | ------------------------------------------------------------------- |
+| `bcubc` | `brew upgrade --cask && brew cleanup` | Update outdated casks, then run cleanup. |
+| `bcubo` | `brew update && brew outdated --cask` | Update Homebrew data, then list outdated casks. |
+| `brewp` | `brew pin` | Pin a specified formula so that it's not upgraded. |
+| `brews` | `brew list -1` | List installed formulae or the installed files for a given formula. |
+| `brewsp` | `brew list --pinned` | List pinned formulae, or show the version of a given formula. |
+| `bubc` | `brew upgrade && brew cleanup` | Upgrade outdated formulae and casks, then run cleanup. |
+| `bubo` | `brew update && brew outdated` | Update Homebrew data, then list outdated formulae and casks. |
+| `bubu` | `bubo && bubc` | Do the last two operations above. |
+| `buf` | `brew upgrade --formula` | Upgrade only formulas (not casks). |
+
+## Completion
+
+With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the
+brew installation, so we no longer ship it with the brew plugin; now it only has brew
+aliases. If you find that brew completion no longer works, make sure you have your Homebrew
+installation fully up to date.
diff --git a/oh-my-zsh/plugins/brew/brew.plugin.zsh b/oh-my-zsh/plugins/brew/brew.plugin.zsh
new file mode 100644
index 0000000..ea89008
--- /dev/null
+++ b/oh-my-zsh/plugins/brew/brew.plugin.zsh
@@ -0,0 +1,48 @@
+if (( ! $+commands[brew] )); then
+ if [[ -x /opt/homebrew/bin/brew ]]; then
+ BREW_LOCATION="/opt/homebrew/bin/brew"
+ elif [[ -x /usr/local/bin/brew ]]; then
+ BREW_LOCATION="/usr/local/bin/brew"
+ elif [[ -x /home/linuxbrew/.linuxbrew/bin/brew ]]; then
+ BREW_LOCATION="/home/linuxbrew/.linuxbrew/bin/brew"
+ elif [[ -x "$HOME/.linuxbrew/bin/brew" ]]; then
+ BREW_LOCATION="$HOME/.linuxbrew/bin/brew"
+ else
+ return
+ fi
+
+ # Only add Homebrew installation to PATH, MANPATH, and INFOPATH if brew is
+ # not already on the path, to prevent duplicate entries. This aligns with
+ # the behavior of the brew installer.sh post-install steps.
+ eval "$("$BREW_LOCATION" shellenv)"
+ unset BREW_LOCATION
+fi
+
+if [[ -z "$HOMEBREW_PREFIX" ]]; then
+ # Maintain compatability with potential custom user profiles, where we had
+ # previously relied on always sourcing shellenv. OMZ plugins should not rely
+ # on this to be defined due to out of order processing.
+ export HOMEBREW_PREFIX="$(brew --prefix)"
+fi
+
+alias bcubc='brew upgrade --cask && brew cleanup'
+alias bcubo='brew update && brew outdated --cask'
+alias brewp='brew pin'
+alias brewsp='brew list --pinned'
+alias bubc='brew upgrade && brew cleanup'
+alias bubo='brew update && brew outdated'
+alias bubu='bubo && bubc'
+alias buf='brew upgrade --formula'
+
+function brews() {
+ local formulae="$(brew leaves | xargs brew deps --installed --for-each)"
+ local casks="$(brew list --cask 2>/dev/null)"
+
+ local blue="$(tput setaf 4)"
+ local bold="$(tput bold)"
+ local off="$(tput sgr0)"
+
+ echo "${blue}==>${off} ${bold}Formulae${off}"
+ echo "${formulae}" | sed "s/^\(.*\):\(.*\)$/\1${blue}\2${off}/"
+ echo "\n${blue}==>${off} ${bold}Casks${off}\n${casks}"
+}