Launch Sublime Text From A Cygwin Terminal

back to tech articles
Sublime Text 3

This same logic can be applied to loads of applications. Today we are going to add a tiny bash script to simplify life by opening our current project/directory in the Sublime Text 3 editor.

Mac programmers will be used to this functionality from TextMate which provides this “hook” by default.

We need to create a new bash script which sits in the PATH for cygwin. You can easily find out what is in your path using the following command:

1
$ echo $PATH

That will dump the contents of your PATH. Somewhere in there you will see /usr/local/bin/. That’s where we are going to add our little script, and here’s how we do it:

1
$ vi /usr/local/bin/slime

That will create a new file called slime (heehee). Next we add the script contents.

1
2
#!/bin/sh
/cygdrive/c/Program\ Files/Sublime\ Text\ 3/sublime_text.exe $1 &

Note that the back slashes \ escape spaces. Just copying and pasting the path won’t work; you will need to escape those spaces as above.

This script is very simple. We are calling sublime_text.exe using an absolute path and passing a single parameter (our directory), which is picked up by $1 and then our ampersand & is telling the system to run this command as a background process, rather than link it to the terminal process (otherwise cygwin would wait until you were finished with Sublime before we could use it again).

So that’s our script done. Save and exit. Now make sure that it’s executable by doing the following:

1
$ chmod +x /usr/local/bin/slime

After that, you are done. Easy, yes? Now you can launch sublime from the current directory by simply typing slime .

1
$ slime .

Laslty, you might want to call your script something like sublime or sl3, instead of slime!

Have fun.