Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening Sublime Text from Bash on Ubuntu on Windows

Tags:

I can't seem to figure out how to open Sublime Text 2 from Bash on Ubuntu on Windows. Ultimately I would like to be able to use subl . to open the contents of the directory I am in.

On my machine, Sublime Text 2 is installed at C:\Program Files\Sublime Text 2. sublime_text.exe is located in this directory. In Bash on Ubuntu on Windows, I can access any files located on C through /mnt/c/.

I tried setting an alias: alias subl="/mnt/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe". However, upon trying subl . I get the following error:

cannot execute binary file: Exec format error

How can I set this up properly?

like image 733
Sara Fuerst Avatar asked Oct 19 '16 15:10

Sara Fuerst


People also ask

How do I access Sublime Text from command prompt?

Open command prompt and type sysdm. In Advanced tab, select Environment variables. Under system variables, select variable named " Path " and click Edit . Add " C:\Program Files\Sublime Text; " to the end of the existing string. Save the changes and restart command prompt.


2 Answers

It's now possible to launch Windows executables (like Sublime Text) from the Bash on Ubuntu command line.

You should also be able to set an alias to use it from the command line (as you were trying to do). Mine is as follows (and works fine):

alias subl='"/mnt/c/Program Files/Sublime Text 3/subl.exe"' 

Note the second set of quotes: this is necessary because of the spaces in the file path. Alternatively you can escape the spaces (as you did in your example).

like image 75
Nick F Avatar answered Oct 01 '22 05:10

Nick F


Nick F's answer is correct, but there is an important caveat.

If your intent is to edit Linux files using Sublime Text, then you should reconsider. Doing so can cause data corruption, as I've discovered first hand.

See here for more details on why: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

I realize this is an old post, but I'm hoping this will serve as a warning to other users attempting to set up Sublime Text to edit Linux files.

like image 42
Sam D Avatar answered Oct 01 '22 05:10

Sam D