Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a command in cygwin to run Sublime Text?

Tags:

bash

cygwin

I'm trying to mimic the subl command in iterm for mac computers in cygwin.

Basically, I want to be able to open a current folder from cygwin by typing subl .

I haven't found any good instructions. I know where my .bashrc file is located. I just dont know what to do to create the command subl and make it so that the path following subl opens with Sublime.

Can anyone help?

like image 225
Daniel Breen Avatar asked Mar 14 '23 18:03

Daniel Breen


2 Answers

You'd want to make an alias and source it from bashrc.

Example

Create a file ~/.bash_aliases with:

alias subl='/cygdrive/c/sublime.exe' #make sure this command is correct for you

Now in ~/.bashrc do:

source ~/.bash_aliases    

Log out and log back in, and subl . should work

like image 80
Marc Young Avatar answered Mar 27 '23 02:03

Marc Young


Assuming you want correct behaviour when doing subl ~, a simple alias or adding Sublime Text to your PATH will not work.

You can use the following bash function instead (put it in your .bashrc):

function subl {
    cygpath --windows $@ | sed 's/\\/\\\\/g' | tr '\n' '\0' | xargs -0 -n1 /cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe
}

Note that when passing paths to xargs you need to 1) escape the backslashes, 2) use the NUL character as argument delimiter for it to work with paths with spaces.

Edit: Use subl.exe rather than sublime_text3.exe so that it would detach itself from the terminal.

like image 20
Alexander Revo Avatar answered Mar 27 '23 03:03

Alexander Revo