open text file with 'Sublime text3' in terminal - terminal

I could open the file with Textmate using mate.
mate file.txt
I'd love to do the same thing with sublimetext3.

You need to create symbolic link:
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /bin/subl
And launch sublime as subl

Related

How to Open a File in Sublime3 from the Command Line on Mac OSX

I was following some intructions online to set up a link so that I can open a file in sublime from my terminal.
I cd into /usr/local/bin I see brew and subl.
Then, I followed the instructions to set up the symbolic link.
In the terminal, I typed ln -s "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Then I saw File exists in the terminal
However, when I tried to subl index.html,
I saw this message command not found.
Please advise
Thank you so much for all the answers. I found out that it was an administrative restriction because I was using a work laptop. I resolved it by re-installing sublime text using homebrew. Now, it's working fine.
brew cask install sublime-text
Thanks again.
First up, check your own $PATH by running: echo $PATH. It should return something like this
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Make sure /usr/local/bin is in the path
Then run
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Note that the directory sublime text 3 is in is
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
and not
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
Which is what you ran. Hope this helps.
It's not due to administrative restriction and you don't have to re-install sublime text.
As File exists suggests, the file has already exist, that's why your typing doesn't work.
Run rm /usr/local/bin/subl first to delete the exist file.
Then run ln -s "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl should solve your problem.
Take me for example,
my app is named Sublime Text 3 instead of Sublime Text.
I ran ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl as people suggest.
It didn't work due to the wrong path while the subl file created.
So I had to delete the existed file using rm /usr/local/bin/subl.
Then ran ln -s "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl instead.
All things work now!!!
I am on El capitan and what worked for me was
running ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
This only works if you check how your extension is named under info
Also on the terminal you can't call sublime because you created it as subl instead so you have to write that in terminal
and then in terminal running subl . (to open a file )

cannot get sublime text 3 command line tools to work

I had sublime text 2 command line tools working. When I downloaded Sublime Text 3, I could not get the command line tools to work. I've tried every answer here: Open Sublime Text from Terminal in macOS. When I type:
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
I get back:
ln: /usr/local/bin/subl: File exists
but no matter what I do I still get back -bash: subl: command not found
Remove the existing link first. It must be a broken link.
List the contents of the directory and you'll see that the link is broken:
$ ls -Al /usr/local/bin/
Output from the above command will show that the existing link is pointing to a non existing file. So delete the broken link:
$ rm /usr/local/bin/subl
You might need to use sudo for the above command.
Now you can create the symlink:
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
I had the same issue and nothing seemed to work. Also, if you have Sublime 2, remember to use:
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
I was not getting it right at first because I forgot the version!

Why isn't Sublime Text link created?

I'm trying to get Sublime Text 2 to open from Terminal. I'm using the following:
MacBook-Pro:project2 myusername$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln: /Users/myusername/bin/subl: No such file or directory
I'm not sure what is wrong. I'm following all the examples out there. Am I missing something?
Here's the output of an echo $PATH (updated path):
/Users/myusername/bin:/Users/myusername/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
This is on OSX 10.11.1
You most probably do not have a bin folder in your home directory. Create one by using
mkdir ~/bin
This will create the bin folder in your /Users/yourusername/ directory. In terminal the ~ is short for your home.
You will also have to append this folder to your path, i.e. create (or edit if it exists) a .profile file in your home directory and give it this content:
export PATH=/Users/yourusername/bin:$PATH
You will have to open a new terminal for this change to take place.
Use one of these 2 commands:
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl ~/bin/subl
or
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Why do I get "subl: command not found"?

I am trying to access and manipulate the .gitignore file in Sublime via the terminal and I ran into this:
subl .gitignore
-bash: subl: command not found
Why can't it find it?
From the official documentation:
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

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