Open Sublime Text 2 from the Terminal

Posted by Andrew on June 17, 2013

As seen here by artero

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl.

Sublime recommends using these instructions to symlink subl but I think subl is hard to remember and most of us don't use the folder they recommend. Most of us have the following in our PATH:

export PATH=/usr/local/bin:(...)

Setting up Terminal

The following command symlinks sublime to subl

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

If you had to add /usr/local/bin to your PATH, run the following command before continuing:

source ~/.bash_profile

This will reload your .bash_profile with the newly added directory.

Testing

Open a Terminal window and run:

sublime filename (replace "filename" by an actual file name)

or

sublime foldername (replace "foldername" by an actual folder name)

or even

sublime . (to open the entire current directory)