Remove Brews Unused for >= 3 Months - homebrew

Is there a way to remove brews that haven't been used for some time period - say 3 months or more?
I want an easy way to remove all the dependencies I installed for a 1 off thing then forgot to cleanup.

You can do brew cleanup -s, which would cleanse the cached artifacts.
And you can also run brew outdated, which would give you some hints which can be removed.
Homebrew is not that smart to figure out your usage, because it does carry the database to do it. :)

Related

How do I minimize opencv build after installation?

It's been a long time since I last built opencv, contrib and all. The last installation I did, I recall being able to shrink the size of the installation after it was done; presently the file "build" is 28 gigabytes. My previous installation was able to be reduced in size to about 12 gigabytes after installation by removing files that are only necessary for installing and building, but not running. I have since forgotten what these files are that can be removed, and the installation tutorial that told me which ones were able to be removed. Can some shed some light on which files in my build folder can be removed after my release and debug builds have been installed?
If your intention is to extract the "bin/ include/ lib/ share/" QUAD and remove the entire cmake build tree, there is a simple thing you can do:
cd /path/to/cv/build
DESTDIR=/tmp/lalala make install -j7
Then you'll find what the QUAD in /tmp/lalala/path/to/your/original/install/dir. If that's all you need, rm -rf /path/to/cv/build.
If you are not using Linux/Unix & make however, let me know in the comment and I'll edit the answer.
Love your spiderman movies, btw. :-)

How to use `homebrew install --head` without first uninstalling?

brew install --head <formula> installs a formula from master (usually). But it feels useless to me, because it fails if you've already got that formula installed due to a link conflict error. (Not even --force works.) Therefore you always have to do brew unlink <formula> first, or uninstall entirely.
I would have expected there to be a way to install a formula without linking it somehow, but apparently not.
Ultimately what I want is to have two copies installed, one the proper release, and one built from master. But the proper one should always have the link. (I would have like to have had another link like /usr/local/bin/<formula>_HEAD, but that's another issue.)
As a workaround, I can copy the formula and give at new name, but that seems gross, and you can't have a "--head-only" formula it seems, so I'd have to keep the version info up to date in the copy as well.
Maybe I need a totally separate installation of Homebrew? But that seems like overkill.

Made an edit to homebrew formula, now I want to save it

So I've made an edit to the tmux formula in homebrew, but now I'm starting to think about how I can keep that change between machines without forking and maintaining my own version of homebrew.
If I do fork homebrew, I would just have to edit and install script to point to my location, but would the formulas locations still be maintained?
So I guess my question is what are my options here? Should I fork homebrew or just make a note of the changes?
You can make your own tap. The easiest way is to create a repository on GitHub called homebrew-self. Your custom formula goes in the root of the repository. Then, you can use it in Homebrew by running
brew tap <your github username>
If you're modifying a formula that's already in Homebrew, though, the easiest (and best) way is to submit a pull request containing your changes.

Get all recommended keg-only environment variables

As I'm going through a bit of cleanup / rebuild on my homebrew, I'm watching a bunch of messages like this go by:
This formula is keg-only: so it was not symlinked into /usr/local.
Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/libxml2/lib
CPPFLAGS: -I/usr/local/opt/libxml2/include
I am very likely to build software that I would like to link against the homebrew versions as opposed to the OS X versions. I am also very unlikely to remember which libraries were keg-only, or track them down appropriately during some late-night ./configure; make; make install session.
Is there a way for Homebrew to cough up a list of all such flags (perhaps in an easy-to-set environment variable format) for those times when I'd like to be reminded of all my keg-only libraries?
Not really.
If this concerns you, the best fix would be to set up your own software as a Homebrew formula, because that build process will automatically include the include and link paths for all keg-only packages. (Look up "superenv" for details.)

How to migrate a Homebrew environment to another computer?

What is the preferred method of exporting a homebrew environment so I can synchronize my workspace between computers? Seems like there should be something similar to composer.lock or pip freeze. Is there a better way than brew list > brews.txt?
There is a better way: brew leaves.
This command prints a simple list of installed formulae which are not dependencies of any other formulae. Essentially this lists everything that was manually installed or is a leftover dependency from a removed formula.
$ brew leaves
apple-gcc42
bash-completion
brew-cask
git
[...]
There's no built-in means of using brew leaves output to install, but just having a clean list of manually-installed formulae is a step in the right direction.
Thanks to this Gabe Berke-Williams for writing about this: http://robots.thoughtbot.com/brew-leaves
Homebrew Bundle seems like a pretty great solution.
There is not a better way, and there are no current plans to make one.
Source: https://github.com/mxcl/homebrew/issues/17771
Use git! Maintaining repos for environment setup scripts is a pretty slick approach.
I highly recommend using a script to set up a development environment in the first place. thoughtbot has a really lightweight approach that provisions a development environment, including a bunch of brew formulas. https://github.com/thoughtbot/laptop. GitHub just open sourced boxen for this (and much more), but it has a somewhat steeper learning curve.
As you can see from the thoughtbot/latop readme, the entire install is a one-liner. If you want different packages, fork the repo and add whatever you use. This only covers the initial install, but it is a fantastic start.
For ongoing synchronization of development environments, including updating your preferred homebrew setup, you might want to try a 'dotfiles' approach. Zach Holman has a great approach detailed here: https://github.com/holman/dotfiles
If you want to tweak or update anything, just make the appropriate changes to the script (holman's dot script does the ongoing update stuff). Commit, push, pull down from any other environments.

Resources