Sublime Forum

Command to start Sublime Text X from terminal?

#1

Is there a way to start Sublime Text X from the terminal? I am on OSX and it would be nice to be able to set Sublime as the default editor for git commit messages etc. (Similar to TextMate’s "mate"command, and MacVim’s "mvim"command.)

(Of course, I can use /Applications/Sublime\ Text\ X/Contents/MacOS/Sublime\ Text\ X, but that is a bit cumbersome)

Cheers,
Helge

0 Likes

#2

A binary launcher is definitely the ideal way to go so that you can set it as a default editor for tools.

In the meantime, I added the following alias to my ~/.bash_profile

alias slt='open -a "Sublime Text X"'

Then I can do:

slt my_stuff.py

Or, create a new project or add to the current project, I do:

slt folder/to/add/
0 Likes

#3

I lieu of a binary, that is an excellent stopgap solution. Thanks.

0 Likes

#4

No problem. It’s been working great for me. Would still like to see X as an OSX registered .app so that it can be assigned as a default editor for certain filetypes and such…

0 Likes

#5

Would also love to be able to set my EDITOR environment variable to point to Sublime Text 2, so that it would integrate into command line tool usage: for example, run “svn commit” and have Sublime Text 2 pop open for me to type in a commit message.

0 Likes

#6

I don’t have a Mac at hand to test this on, but you should be able to create a simple bash script that looks something like this:

#!/bin/sh open -a "Sublime Text X" "$@"

Mark it executable

chmod +x sublime.sh

and you can now run

./sublime.sh filename filename2 filename3

And you can set it as your EDITOR :smile: if you put it in /bin you won’t need the path (./) either.

0 Likes

#7

Is there an equivalent for Linux/Ubuntu?

0 Likes

#8

On Linux, you can just pass the command line arguments directly to the excutable.

Personally, I have a symlink to sublime_text in my path called ‘subl’, so I can just type “subl readme.txt” to open a file.

0 Likes

#9

I prefer:

slime dir/file

:wink:

0 Likes

#10

[quote=“jps”]On Linux, you can just pass the command line arguments directly to the excutable.

Personally, I have a symlink to sublime_text in my path called ‘subl’, so I can just type “subl readme.txt” to open a file.[/quote]

Could you offer some steps for this? I’m moving from Windows to Ubuntu, and can’t get this to work. I’ve tried following linux.byexamples.com/archives/19 … e-symlink/ but am failing.

0 Likes

#11

I would also like to be able to open files from the commandline with Sublime Text 2. I’m on Ubuntu and don’t know how to make a symlink. Could anyone help?

0 Likes

#12

Hi guys,

Old topic, I know, but I have a symlink for those on Ubuntu looking to be able to open Sublime Text 2 directly from the terminal.

sudo ln -s /home/me/Applications/Sublime\ Text\ 2/sublime_text /usr/bin/subl

This will create a symlink to open files when you write

subl folder_name/file_name

If you want to change your call code (slime is cute), then just change the last part of the above code to be

/usr/bin/your_name_here

Good luck!

0 Likes

#13

Hello,
I have set up a symlink as suggested in: sublimetext.com/docs/2/osx_command_line.html and have also set ‘subl -w’ as my EDITOR, however I get the following error whenever I go to edit my crontab:

$ crontab -e
crontab: subl -w: No such file or directory
crontab: “subl -w” exited with status 1

Does anyone have the same problem or know what is going wrong here? Every other time EDITOR is invoked it works perfectly, I only have a problem with editing my crontab.

Thanks,
Matt

0 Likes

#14

With the hint from,

sublimetext.userecho.com/topic/9 … -for-subl/

In addition to the ‘subl’ setup, I created a ‘subl_wait’ bash script for it,

#!/bin/sh subl -w $*

and set the following in my environment

export EDITOR='subl_wait'

This seems to work nicely for my ‘crontab -e’ and ‘git commit’.

If this works perfectly for everyone, perhaps it should be added to the official docs. =)

0 Likes

#15

This can be done easily. I have my sublime text binary installed in my PATH, and I have the following setup in my .bash_profile to setup the EDITOR variable properly:

export EDITOR="$(which sublime) --new-window --wait"

Using $(which sublime) will get the full path to the executable. The options --new-window and --wait are useful when using sublime as your default EDITOR: --wait tells sublime text to wait until the window is closed to return to the terminal. --new-window is just handy because it will open the file for edit in – you guessed it-- a new window! Not neccessary, but i have lots of files open in sublime all the time and it just helps me keep track of what’s what.

To see all sublime command line options on *nix, use --help.

Hope this is useful.

0 Likes