Sublime Text 2: subl shell command often fails to open files - shell

I have Sublime Text 2 installed on a Mac, and have made a link on the command line as described in the docs.
When opening files from the terminal, as in:
$ subl foo.txt
A Sublime Text window will open, but inside that window foo.txt will only open about one out of every three times or so. I've tried moving the link to a different folder in the path, creating it with sudo, etc., but no luck so far.
Any idea how to fix this?

Had the same problem for a while now. Add the following line to your .bash_profile:
alias subl='subl && sleep 0.1 && subl'
Now you can use subl filename_to_edit to open it.
If you are not sure if you configured subl command correctly, do the following. Run the first command for ST3 or the second for ST2:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Make sure that ~/bin is in your $PATH. Then do the first step with .bash_profile.
Finally works as it should! Credit goes to these guys and chrisf for improvement.

I remember running into problems with subl before. And had to come up with a function to see if Sublime is running, if not launch it, see if it loaded. Then use "rmate" bash script and the associated "rsub" Sublime Text Package plugin to load in the specified file. However you should be able to use the OSX open command should work for what you need. I would also give the latest Sublime Text 3 Beta a try.

Related

I cannot able to connect sublime text 2 from my terminal

When I am writing open subl in my terminal it's showing The file /user/imtiaz/sublime does not exis can some one please help me for this one thanks
Assuming your account has administrator access, run the following command from Terminal:
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
The sudo command will ask you to enter your password, which you should do. The symbolic link will be created in /usr/bin, which is already in your path. You should now be able to run
subl filename.ext
and open the filename in Sublime.
If you're just getting started with Sublime, however, I would strongly recommend using Sublime Text 3 instead. It has many major improvements over ST2, and even though it's technically still labeled "Beta", it's rock-solid. I've been using it for over 2 years without any major issues. ST2 has some bugs in it, which will never get fixed. Once installed, the first thing you need to do is install Package Control, which allows you to easily manage plugins. Many plugins now only support ST3, or their ST2 versions are no longer being updated.
If you do install ST3, change the above command to
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
as the app is named Sublime Text.app instead of Sublime Text 2.app.

Sublime Text 3 'subl' command still linked to Sublime Text 2

This is driving me crazy. I'm running OSX and until today I had Sublime Text 2 installed. After installing Sublime Text 3, when I enter the 'subl' command the terminal logs:
Unable to find application named 'Sublime Text 2'
I've tried everything. I've tried
$ rm ~/bin/subl
Then
$ ln -s /Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl ~/bin/subl
I've also tried going in to usr directly and removing the subl command. When I do this, the subl command will sometimes work while I remain in one directory, but once I switch directories it goes back to giving me the message
Unable to find application named 'Sublime Text 2'
With Sublime Text 2 I had subl entered as an alias. I also tried going in and unaliasing subl like this:
unalias subl
And I've tried re-creating the alias using
/Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl
Again, this will work for a while, but once I change directories it stops working.
Any advice on what to try next? I'm at a loss. I can't understand why it works for a while, then stops working.
Check your .bashrc file, and .bash_profile and see if it's aliased in there. Both of these are in your home directory ~.
nano ~/.bashrc
nano ~/.bash_profile
No need to sudo as you own these documents.

Sublime 3: Subl not working

Before today I had Sublime 2 and 3 on my computer. When I ran the subl command in the terminal it would always open Sublime 2, which I never use anymore. Therefore I got rid of Sublime 2. Now my subl command does not work at all. All I get is subl command not found.
I understand that I have to put a subl binary file into my bin folder. I was just wondering what might be the best way to go about doing that. Any insight on this particular instance would help.
Thanks in advance,
According to their website:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
(The command is almost identical to the one for version 2.)
If you have a fresh install of OS X, this will probably fail for you. First, create a ~/bin directory under your home and add it to your path. This will vary by your shell, but if you use bash..
mkdir ~/bin
echo "export PATH=$PATH:~/bin" >> ~/.bash_profile
source ~/.bash_profile
Then you should be able to run the ln command and subl to your hearts content.
As a side note, a simplified version of this can be accomplished with the open command for any app. Try open -a TextEdit hello.txt for similar effect. I've aliased this for a hex editor that didn't offer a CLI launcher like subl.
Try this: (it worked for me)
alias subl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"
alias nano="subl"
export EDITOR="subl"
Shortly after I posted this question I found the answer. The issue was that because the subl file in my bin or binary folder was tied to Sublime 2, when I uninstalled Sublime 2 it also uninstalled that binary.
All I did was copy the subl file from Sublime 3 into the bin or binary folder. I did have use the terminal in order to get down to the bin folder. Once I opened both folders with the terminal I just copied the subl binary from Sublime 3 to my binary folder.

Sublime Text 2 and Terminal

So I'm trying to make it so that I can start Sublime Text 2 from the terminal through this command, given by the Sublime Text documentation:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
But for some reason this is not working. I get this error from my terminal:
ln: /Users/connorblack/bin/subl: No such file or directory
Can anyone help me with this?
Other details: I have SB2 in my Applications folder. I'm trying to do RoR development.
Your problem is that you don't have a ~/bin directory, just do
mkdir ~/bin
And then retry the command, it should work
Note that to use subl from this folder you will still need to add it to your PATH, add this line to your .bashrc or .zshrc:
export PATH=$PATH:/Users/connorblack/bin

Installing Sublime Text's command line tool 'subl' in terminal, permission denied?

I'm tryng to use Sublime Text from the terminal, for example by typing subl.
I'm following the steps from Sublime Text's website:
Setup
The first task is to make a symlink to subl. Assuming you've placed Sublime Text 2 in the Applications folder, and that you have a ~/bin directory in your path, you can run:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
I keep getting permission denied : ~/bin/subl: Permission Denied
I have been searching around for a similar problem but can't find one that's applicable. Can someone point me to the right direction?
I am assuming that you don't have the bin directory. You can do the following:
cd
mkdir bin
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln -s will create a alias of the subl file in your bin directory and you will be able to run the command.
If this still doesn't work you will have to edit your .bash_profile. You can do it by following commands: (NOTE: For this to work you need to have done the above steps already.)
Open your .bash_profile:
cd // this will get you back to home directory
vim .bash_profile // this will open your .bash_profile file
Edit .bash_profile: press I to get into "insert" mode and add following:
export PATH=$PATH:~/bin
Save and exit. Press Esc to get into command mode:
:wq // saves and close file
exit // exits terminal
Reopen the terminal:
subl --help
That should bring up the help for Sublime Text.
My personal preference for the path to the third-party application-specific symbolic links (e.g. subl, brew, github, mate, etc) is:
/usr/local/bin
Why not /usr/bin/?
/usr/bin is a "sacred" place. It is generally recommended to store static binaries that are maintained by package management systems. subl is not this case.
subl is not stable enough to be stored in /usr/bin with other basic BSD binaries (e.g. find, man, make, etc). You must modify/delete subl symbolic link manually if (a) the developers of Sublime Text Editor decide to change its app name in the future releases (as BBEdit Lite was changed to TextWrangler after version 6.1), or (b) you may simply wish to uninstall Sublime Text Editor.
Therefore, I suggest you execute the following line, assuming /usr/local/bin/ exists:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Check whether "~/bin/" is included in the path.
A better options is to create the symlink in /usr/bin directory instead.
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl

Resources