-
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.
Note: External commands are a new and somewhat experimental feature. Feedback is appreciated.
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
. (Homebrew internally finds commands with 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
. To run these commands, that folder should be added to your $PATH
.