Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a Sublime project from the command line without opening a blank window

I am trying to figure out how to open a Sublime Text project from the command line.

If I type subl foo.project for a project that is not open, it opens the project. But if I do this for a project that is already open, it opens a blank window for some reason. I have no idea whether this is a bug or intended behavior.

Is it possible to come up with a command or shell script that takes a project filename, and opens it if it is not open, but focuses it if it is open? If so, how can I do this?

I am using Sublime Text 2.0.1 and OS X 10.8.4. I have subl symlinked to /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl.

I found this post on UserEcho and this post on the forum but there haven't been any meaningful responses. Other than that, I haven't found anything else about this bug.

EDIT: I updated to the Sublime Text 3 beta and I still experience this bug. I haven't found a fix or workaround.

like image 824
Elias Zamaria Avatar asked Jun 26 '13 17:06

Elias Zamaria


People also ask

How do I open Sublime Text from command prompt?

Open any program file in the sublime editor and Right-click (context menu). You can see the Cmd menu in the Context menu options. Click on it. The command prompt will be opened through which you can compile and run your program.

How do I get Sublime Text from terminal?

Sublime by default does not have terminal integrated. Terminus is a cross-platform terminal for sublime. To install Terminus – COMMAND PALLET [ CTRL + SHIFT + P ] → INSTALL PACKAGE → TERMINUS.


3 Answers

This is a known bug in Sublime Text 2/3 on OSX. The Developers have not made many comments about it, so it might not be something they're working on in the near future.

As for the bash script, you might want to head over to 'Ask Ubuntu'. Lot's of Unix gurus over there who might have a quick fix for you.

like image 115
JcKelley Avatar answered Oct 09 '22 15:10

JcKelley


I'm using this combination to switch between projects

alias sp='subl --command "close_project"; subl --project'
sp myproject.sublime-project

Sometimes though the empty window still appears, then I think you may need a delay

alias sp='subl --command "close_project"; sleep 0.2; subl --project'
like image 45
Gregory Vincic Avatar answered Oct 09 '22 16:10

Gregory Vincic


It is a bug, still present in my build 3059. A workaround is to wait until the Sublime window is open, and then open the file.

Eg. put the following in your .bash_profile:

alias edit='subl && sleep 0.1 && subl'

(And don't forget to run source .bash_profile to refresh.) On my computer 0.1 seconds was quick enough, but it can be that this value has to be bigger on slower computers.

like image 40
littlegreen Avatar answered Oct 09 '22 14:10

littlegreen