How can I remove dependencies recursively in Homebrew?
A simple way to solve the problem of accumulating dependencies of deinstalled things is to periodically run brew leaves and compare it against a list of wanted leaves, and recursively remove everything else.

The following works, but of course is not very readable:

1) Show all the leaves minus the ones in your wanted list:

$ brew leaves | egrep -v 'bcwipe|brew-cask|lftp|mmv|mobile-shell|mplayer|node|octave|python|zsh'


2) Once you have adjusted the list (i.e. added new keepers), get rid of the rest:

$ brew uninstall `brew leaves|egrep -v 'bcwipe|brew-cask|git|lftp|mmv|mobile-shell|mplayer|node|octave|python|zsh'`


This usually has to be called a few times in a row to get them all, and the final call should be followed by a

$ brew cleanup


To beautify a bit, the list of keepers can of course be kept in a file somewhere.