-
Notifications
You must be signed in to change notification settings - Fork 5
External Commands
Homebrew, like Git, supports external commands. This lets you create new commands that can be run like:
brew mycommand --option1 --option2 formula
without modifying Homebrew’s internals.
External commands come in two flavors, Ruby commands and shell scripts.
In both cases, the command file should be +x
(executable) and live somewhere in your $PATH
.
Internally, Homebrew finds commands with /usr/bin/which
.
An external command foo
implemented as a Ruby command should be named brew-foo.rb
. The command is executed by doing a require
on the full pathname. As the command is require’d, it has full access to the Homebrew “environment”, ie, all global variables and modules that any internal command has access to.
The command may Kernel.exit
with a status code if it needs to; if it doesn’t explicitly exit then Homebrew will return 0.
A shell script for an command named foo
should be named brew-foo
. This file will be run via exec
with some Homebrew variables set as environmental variables, and passed any additional command-line arguments.
Variable | Description |
HOMEBREW_CACHE | Where Homebrew caches downloaded tarballs to, typically ~/Library/Caches/Homebrew . |
HOMEBREW_CELLAR | The location of the Homebrew Cellar, where software is built to. |
HOMEBREW_LIBRARY_PATH | The folder containing Homebrew’s own application code. |
HOMEBREW_PREFIX | Where Homebrew installs software to, usually /usr/local . |
HOMEBREW_REPOSITORY | If installed from a Git clone, the repo folder. (That is, where Homebrew’s .git folder lives.) |
Note that the script itself can use any suitable #!
line, so an external “shell script” can be written for sh, bash, Ruby, or anything else.
Homebrew comes with some sample commands in Library/Contributions/examples
.
NOTE: These commands are largely untested, and as always, be careful about running untested code on your machine.
Scrapes a formula’s homepage to get more information: https://gist.github.com/475200
Does brew update followed by brew outdated: https://gist.github.com/514247
Does a rebase on “brew update” instead of a merge: https://gist.github.com/493669
Simple support to start formulas using launchctl, has out of the box support for any formula which defines startup_plist
(like e.g. mysql, postgres, redis u.v.m.): https://gist.github.com/766293
Install any gem into a self-contained Homebrew cellar location: https://github.com/josh/brew-gem
Get short descriptions for Homebrew formulas or search formulas by description: https://github.com/telemachus/brew-desc