Command Line Sublime
Getting Sublime Text 3 to run from the command line is not magic. The original documentation assume a relatively high degree of familiarity with the unix environment and omits key details. We will attempt to clarify this process.
subl .
Is it your wish to possess this kind of power?
Bill's words to the wise...
When you see things like "/Applications/yaydayd/moreyadyady", the "" are mandatory and generally speaking, paying attention to all details whether or not the detail means anything to you, will make you a happier coder.
In order to run sublime from the command line subl .
Where subl
represents the command to open sublime and the .
is an argument, the argument represents what to open with sublime, .
representing the contents of the current directory but one could open any location they cared about.
For example running subl ~/Dropbox/code/ruby_example.rb
would tell sublime to open the file ruby_example.rb stored in ~/Dropbox/code/
The original sublime documentation indicates that running below line of code at your bash prompt will enable a user to open sublime from the command line.
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
This code is creating a symlink between the actual subl executable and the ~/bin
directory that can be called upon by typing subl
at the bash prompt from anywhere inside your file system. This code makes some assumptions about you the programmer. The above line may or may not work 'out of the box'. The below tutorial will take you through all the steps required to make the above line of code work. If things stop working for you, please email stuck@codeuion.io
Assumptions The Above Makes About You the Programmer.
Your computer has the directory
~/bin
which is the same as/Users/yourusername/bin
and in the case of John Davison,~/bin
is the same as/Users/jd/bin
.~/bin
has been added to yourPATH
You know what the
PATH
is.
Lucky for you, we don't live in a world dominated by assumptions about the technical state of the people we interact with.
Step by Step Instructions required to run Sublime from the command line.
- Check that you have
~/bin
available to your machine.
ls ~/bin
- Create
~/bin
if it doesn't exist.
mkdir ~/bin
- Verify that you have Sublime Text 3 installed correctly on your system.
ls "/Applications/Sublime Text.app/Contents/SharedSupport/bin/"
If you don't have Sublime installed, please visit http://www.sublimetext.com/3
- Create a symlink between the actual sublime executable and
~/bin/subl
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
- Caveat Step, verify that you have
~/bin/subl
in yourPATH
The PATH
is a list of locations that unix will for programs that correspond to the commands you write in your terminal.
echo $PATH
Look at the output of the above command and attempt to find something that looks like :/Users/yourusername/bin:
. Note, yourusername will show whatever your actual user name is. John Davison's machine's username at time of this publication was jd and therefore, his validated path contained :/Users/jd/bin:

If you have /Users/yourusername/bin
in your path, type subl
auto-magically you should find sublime opening a new window and/or starting if it wasn't already running.
If you do not have /Users/yourusername/bin
in your path, follow the below instructions to add it to your PATH
.
1. Ensure your mac will show all hidden files and folders in finder.
Any file or folder that starts with a `.` is 'hidden' for example ```.bash_profile``` and ```.git/```
1. Run ```defaults write com.apple.finder AppleShowAllFiles YES``` in the terminal
1. Run ```killall -HUP Finder``` in the terminal.
1. Run ```defaults write -g AppleShowAllFiles YES``` in the terminal.

1. Restart and open Sublime
Open the file
.bash_profile
located in your 'home' directoryAdd
export PATH=$HOME/bin:$PATH
to the top.bash_profile
, don't worry about other information that may be present in.bash_profile
and don't worry if the contents of your.bash_profile
do not perfectly match the contents of the below screenshot.
Save the changes you just made to
.bash_profile
, close the file.Restart your terminal and verify that
/Users/yourusername/bin
appears when you runecho $PATH
You should now be able to type
subl
at the command line and have sublime open. You can typesubl .
to make sublime open the contents of the current working directory as well.You can verify that all of the above has worked by typing
which subl
and get output that looks similiar to the below, but instead of/Users/jd/bin/subl
you should see/Users/yourusername/bin/subl