Open sublime text 2 from command line on windows

less than 1 minute read

In Mac, you can open sublime text 2 from terminal, and it’s really handy.

I wanted to replicate the same thing on windows, so wrote a simple script that enables it.
Once you run this script, you can do the following things from command line.

subl // this will open sublime text 2
subl . // open sublime text 2 with folder side bar.

For example, if you do it in c:\dev\trunk, sublime text will open with folder that is based on c:\dev\trunk.

To run the script, copy the below, and in the command prompt (not powershell prompt), right click and paste it. You must have powershell installed if you are not on windows 7 or Vista

[sourcecode language="bash"]

REM Begin Copy
Set-Content "C:\Program Files\Sublime Text 2\subl.bat" "@echo off"
Add-Content "C:\Program Files\Sublime Text 2\subl.bat" "start sublime_text.exe %1"
if (!($Env:Path.Contains("Sublime"))) {[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";C:\Program Files\Sublime Text 2", "Machine")}
REM End Copy


You will have to close the command prompt as the path change would take effect when a new command prompt starts.