Homebrew: brew edit with Sublime Text 2

Homebrew gives priority to $VISUAL, so even if you set $EDITOR in your .bashrc it may still default to vim, which is what I was encountering every time I wanted to run brew edit

First, I set both HOMEBREW_EDITOR and VISUAL to Sublime Text 2 in ~/.bashrc

cd ~ 
nano .bashrc

add the following two lines pointing to Sublime Text 2

export VISUAL=subl

… save & exit.

Then make sure that Homebrew understands subl

sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin

I was then able to run brew edit [some package] in Sublime Text 2.

NOTE: having VISUAL set to this editor allows me to use Sublime Text 2 in other instances from within Terminal, not only within the scope of Homebrew.