Skip to content

Instantly share code, notes, and snippets.

@19h47
Last active August 12, 2017 14:46
Show Gist options
  • Save 19h47/148ce90776fd86120fcdff4779c01811 to your computer and use it in GitHub Desktop.
Save 19h47/148ce90776fd86120fcdff4779c01811 to your computer and use it in GitHub Desktop.
Run Sublime Text 3 from terminal with the current sublime-project file loaded

Run Sublime Text with the sublime-project file loaded

The sublime-project is a file that contains all settings for a specific project. The file as to be loaded each time you relaunch Sublime Text.
To avoid that, we are going to launch Sublime Text from terminal with a parameter that is this sublime-project file name.

Set up Sublime Text CLI

Sublime Text bring a CLI tool subl, but we can't used the CLI tool as it is. To use it, we need to do a symbolic link.

Assuming you've placed Sublime Text in the applications folder

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

The ln is a command utility to create link to an existing file. The option -s is used to create a symbolic link. It's an alias.
The /bin folder is a directory in Unix systems that contains the executable programs.

We name our link sublime to be more explicit.

Now we can run Sublime Text just by typing sublime in our terminal.

Source

Definition /bin Doc Unix
Doc Sublime Text
Tutorial by Olivier Lacan

Add a parameter

Now we need to tell to Sublime Text to use the current sublime-project file when we hit sublime in terminal. For this we will add a parameter that will be the name of our sublime-project file.

Go to your project folder

cd /path/to/your/project

Then create a .bashrc file

touch .bashrc

Open the freshly created file and copy paste this code

# [...]

function project_aware_subl {
    project_file=$(ls *.sublime-project 2>/dev/null | head -n 1)
    sublime ${*:-${project_file:-.}}
}
alias sublime="project_aware_subl"

# [...]

Now, from the terminal, at the root of your project, we can hit sublime your_project.sublime-project and Sublime Text will launch with the project-sublime file loaded.

Pretty cool, isn't it? 😎

Source

Tutorial by Bruno Carlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment