UX Design and Development course

Link your Terminal.app to Sublime text

Sublime Text 2 includes a command line tool, subl, to work with files on the command line. This can be used to open files and projects in Sublime Text 2, as well working as an editor for unix tools, such as git and subversion.

The first task is to make a symlink to subl. Assuming you've placed Sublime Text 2 in the Applications folder, and that you have a ~/bin directory in your path, you can run:

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

Like Bash to Sublime on Windows

The concept is similar, but the steps are slightly different. First, on your machine go to your home dir cd ~/, NOT your C:\ drive. We are looking for the .bashrc file.

$ ls

If this file is not there, go ahead and make one.

$ touch .bashrc

Now that this is known or established, add this alias to your .bashrc

alias subl='"/c/Program Files/Sublime Text 2/sublime_text.exe"'

For more, read Launch Sublime Text From the Command Line in Windows

You are not restricted to use subl as your symlink. But I would caution against just using s as this may conflict with other commands used at the prompt.

If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell. reference

But feel free to use variations like sub, st, su, or bl

How to use

If this command works without error, then you should be able to go to any file from within the Terminal.app and use the subl symlink as illustrated in the following example and open a file:

$ subl index.html

All files types are accessible, even (dot) files as well:

$ subl .gitignore


If you run into issues getting this to work, lets examine some ways to trouble-shoot this.

Permission Access

There may be an issue with permissions and your Mac. In the case you are getting a permissions error, simply adding sudo to the command will help resolve this. When you use this, the prompt will ask you for your computer's password.

sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Also note that the cursor WILL NOT MOVE when you are typing in the password. If you make a mistake, don't try and use the delta key as this will not work. Press return and try again.

Directory does not exist

If there is an issue where the ~/bin directory does not exist, simply make one.

mkdir ~/bin

The use of the ~/ in the path ensures that this will place the /bin directory within your home directory no matter your location from within the Terminal.app.

It looked like it worked?

There are issues where it looked like it worked, but nothing is working? There were no errors, but you are not able to open filed from Terminal. First, make sure that you are using Sublime Text 2 or greater. From the Terminal.app prompt, try and change directories to the location of the subl tool.

$ cd ~/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/

If you can make it here, do a ls to make sure that subl exists. If it does not or you are unable to access this directory, check your version.