'Get homebrew to run a script after 'brew install x' or 'brew uninstall x'
I want to automate having a file that tracks all my installed brew packages.
I can do this manually with brew list > somefile
, how ever I want this process to be automated.
Is there a way to run a script automatically after running brew install
or brew uninstall
?
Or is there a better way of doing this I'm overlooking? Thank you
Solution 1:[1]
Yes. You can create functions to run the brew install
or brew uninstall
and add on whatever else you'd like to run.
function bi() {
brew install $@
brew list > somefile
}
function bu() {
brew uninstall $@
brew list > somefile
}
Then instead of running brew install [package]
or brew uninstall [package]
you just run bi [package]
or bu [package]
and your somefile
file will always have an up-to-date list of installed packages.
You'll need to add these functions to one of your startup files: .bashrc
or .bash_profile
, so they will be available with each new bash session.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dean Householder |