Home > database >  Get homebrew to run a script after 'brew install x' or 'brew uninstall x'
Get homebrew to run a script after 'brew install x' or 'brew uninstall x'

Time:05-17

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

CodePudding user response:

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.

  • Related