Sublime Text shortcut on command line (subl)

The Sublime Text documentation “OS X Command Line” references the command line tool, subl to work with files on the command line.

This allows you to open the entire current directory in sublime like this:

subl .

This allows you to open a specific file like this:

subl <file_name>

However, this is not immediately accessible when you download Sublime. Without symlink-ing the command, you will have to type the full path. 

This is how you would use the full path to open a file.

/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl <file_name>

So lets create a symlink

The official docs ask you to target your symlink to ~bin/subl but it may be nicer to keep symlinks contained to existing load paths like usr/local/bin

Find your current load paths by running this command:

$ echo $PATH

You will see all load paths including these default OS X paths:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

How to create subl shortcut for Sublime Text

Run this command in your terminal:

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

What happened?

ln means link, -s means we want a symbolic link

We will create a symlink at usr/local/bin/subl that will point to the original Sublime command. Deleting this link will have no effect on the original file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s