Sublime Forum

Subl command not working as expected anymore

#1

I’ve use subl filename for months, and never had an issue. I have it set up correctly.

However this morning, when I first tried the command, it opens up a blank new document rather than the file. After discussing the matter on irc, I’ve found that subl -w filename works, but the terminal of course waits until editing is completed.

How/why did this change overnight for me? (I can’t think of anything I’ve changed)

This isn’t expected behavior for me, am I expecting incorrectly?

I’m on Mac OS Lion with the newest version of Sublime Text 2.

0 Likes

'subl -n foo' flaky after upgrading to mavericks
#2

I am having the same problem. Actually, the alias has never worked for me at all… I would like to use it in zsh. Anyone have any suggestions?

0 Likes

#3

Just wanted to add that I’m having the same problem. When I switched to zsh (I’m using prezto), suddenly the “subl” command does not open files or directories from the command prompt. In fact, it appears to simply open Sublime Text 2 if it has not yet been opened, and it opens it to the previously open files or directories.

I can confirm that when I use bash, the behavior reverts to normal–“subl .” for example, will open the current directory in a new sublime window.

0 Likes

#4

Correcting an earlier observation: It appears that the behavior is not dependent on bash/zsh, but rather on the state of sublime text 2. If Sublime Text 2 is open, but has no open windows, then “subl .” will open a NEW window, but it will not load the current directory. OTOH, if I first press “Cmd+N” in sublime text 2, then the “subl .” command (or any other subl " command) will open a file or directory in a new sublime text editor window. Odd.

0 Likes

#5

Also, when you drag a file into Sublime Text, when no files open, then “untitled” tab is opened and no content in it. If you close that tab and drag again, then all works.

About all windows restored on next open of sublime - it’s a setting that you can turn off:
“hot_exit”: false,

0 Likes

#6

Just wanted to chime in that this is an issue for me too. If ST is not open, running subl filename will just launch it. Running the command a second time will work as expected.

Sublime Text 2 Version 2.0.1, Build 2217.

Cheers!

0 Likes

#7

Agreed - the state of Sublime seems to be the culprit. FYI - I am seeing same exact issues on build 3008. If Sublime is not running (i.e. was Quit), then “subl .” works as expected. However, if Sublime was running, but no windows were open, then “subl .” opens a new window but with no open project/files. However, “subl -w .” does work, but I really don’t want to use “-w”. :smile: A bug fix would be most appreciated! Thanks, L

0 Likes

#8

This is still broken, right? I’m using build 3059 and I deal with this daily. “subl dir/” sometimes opens an empty window, sometimes opens the directory.

0 Likes

#9

I’m getting the same issue with build 3059. Highly annoying to often have to run subl twice.

0 Likes

#10

I can confirm that subl is unreliable with both ST2 and ST3 in that the specified file is not always opened. Sometimes it works, and sometimes it doesn’t: running the exact same command twice will yield different results (making sure ST is in the same state each time). It’s worst if ST isn’t running initially but I’ve had it fail to open a file even it’s already running.

open -a ‘Sublime Text’ filename is much more reliable but you can’t specify a line number that way. I also tried using the –command argument to subl but that seemed even more flaky. I suspect there’s a bug in the argument processing of subl which is munging things.

I’m on Mac OS X 10.8.5

0 Likes

#11

This probably isn’t for everyone but I have found a workaround for subl’s flakiness:

 If you use the **--wait** option the tool works every time.  

Using this from the shell causes some oddities (luckily that isn’t my use case) but you can mostly work around them by putting the command in the background (with an & at the end of the line). You’ll probably have to write a fully-fledged shell script to get this working seamlessly as it’s beyond the scope of an alias or symbolic link.

0 Likes

#12

Here’s my temporary solution, I threw it in a timeout function and mapped it to sub instead of subl. Just add this to your rc file in Unix.

function timeout {
    perl -e 'alarm shift; exec @ARGV' "$@";
}

function sub {
    timeout 1 subl $1 --wait
}
0 Likes

#13

I have the same problem on OSX 10.9.3 with ST3.
I had ST3 open with 2 files opened. Using
subl .zshrc_backup ST3 window came up but the file was not opened. Instead one of already open files was shown.
Executing just the same cmd again opened it eventually.

For completeness: I am using zsh and have seen this behaviour both with the Oh-my-zsh and prezto frameworks for setting up zsh.

0 Likes

#14

I’ve written a small Bash script that wraps subl reliably for me: https://gist.github.com/felixrabe/4a2673da8e203af824e6

#!/usr/bin/env bash
 
if  $# -eq 0 ]] ; then
  subl -w . &
else
  subl -w "$@" &
fi
 
sleep 0.5
kill $!
0 Likes

#15

same issue here! OSX 10.9, sublimetext build 3065

0 Likes