-
Star
(101)
You must be signed in to star a gist -
Fork
(33)
You must be signed in to fork a gist
-
-
Save adrianorsouza/df4759b0583dcd112da4 to your computer and use it in GitHub Desktop.
| Launch Sublime Text from the command line on OSX | |
| --- | |
| ### Requirements | |
| - Sublime text 2 or 3 installed in your system within `Applications` folder | |
| In order to launch sublime from command you only need to create a symlink `/usr/local/bin/subl` point to sublime app, to do so run the following in the command line. | |
| Sublime Text 2 | |
| ---- | |
| ln -sv "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl | |
| Sublime Text 3 | |
| ---- | |
| ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl | |
| Test it out | |
| ---- | |
| type in command line | |
| subl test.rb | |
| it should open new file `test.rb` sublime text | |
| ---- | |
| NOTE: To accomplish this you must: | |
| have created a directory where you actually place binaries `/usr/local/bin` if not make it before creating a `symlink`: | |
| mkdir -p /usr/local/bin | |
| have `/usr/local/bin` in your PATH environment variable, if not add by running the following command: | |
| echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile | |
| then reload the shell: | |
| source ~/.bash_profile | |
| test again. | |
awesome explanation. Thanks!
Good job!
Thanks for this
I can't seem to get this to work :( Could it be because I have El Capitan OS? I tried all the steps but still get "command not found" when typing subl in the command line.
Sorry @janeygak I haven't tested on El Capitan OS, I'm just about to migrate from Mavericks to El Capitan OS, after I test it out I updated here.
UPDATE:
@janeygak it's a bit late but, I've test it out on El Capitan, and yet it works flawlessly for both ST2 and ST3 ;).
So if you still have a trouble, I guess you may check on of the following steps:
1: Check if the subl command does exists is in your PATH, type in terminal the following command:
$ which sublYou should see something like: /usr/local/bin/subl, if the output is empty you probably haven't to created symlink.
2: Make sure the bin folder from the result above is in your PATH:
$ echo $PATH | grep -o /usr/local/binYou should see in the output: /usr/local/bin, if not, follow the note described at bottom of the gist.
- Lately check if you've created the symlink within the
binfolder and the symlink point to thesublproperly.
$ ls -l /usr/local/bin/Should see in the output: subl -> /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
If none of these works let me know.
@janeygak
I've got same problem in El Capitan
bash: /Applications/Sublime: No such file or directory
It seem that El Captan don't like whitespaces in symlink paths. I also try it with backslashes, but it won't help. If i executed from terminal it works. So i use alias now.
alias subl="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"Just save it in ~/.profile, so it will be executed every time you open a terminal.
@gseidel your approach also works fine as an alias, I think that error was maybe you've tried to create a symlink with backslash or without enclosed quotation mark.
Make sure if you type the command in terminal as follows, enclosed with double quotation mark and without backslash in it:
ln -sv "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublI just tested it out on El Capitan and worked fine, I also updated the previous comment that might help you too.
I see why "sublime: command not found" happens......
check /Applications/Sublime Text.app/xxx and ln -sv "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl.
and make sure 'Sublime Text.app' is same.
Hey I'm having the same problem in OSX 10.11.4.
Sublime symlink sets up fine.
subl
in bash launches Sublime 3 fine.
However, I've tried adding it to git's configuration any number of ways - and none work. Continually get the following error, wheather .gitconfig links directly to the Sublime subl file or to the symlink.
'subl -n -w': subl -n -w: command not found
error: There was a problem with the editor ''subl -n -w''.
Here's the pertinent line from my current git config, as I say, I've tried linking to the file directly also.
core.editor='subl -n -w'
And here's the output of running the ln - sv command above
/usr/local/bin/subl. -> /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
Nevermind! @gseidel provided an answer that works. I added the alias line to .bash_profile.
I have Sublime installed in my Mac's Applications directory (not in my user Applications directory).
~/Applications/Sublime\ Text\ 3.app does not exist. Whereas ./Applications/Sublime\ Text\ 3.app does exist.
I tried the symlink as
ln -sv "./Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
but sublime . does not work. -bash: sublime: command not found
ls -l /usr/local/bin renders the following
sublime -> ./Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl
@dbspin to define subl as your default git editor it's pretty easy, make sure if you got the proper setup within the ~/.gitconfig as follows:
[core]
editor = subl -w
I've seen so many people here having trouble when creating the symbolic link and use the subl command, as $PATH and different versions within the installation folder may differ from one and other, so here is the simplest way to set up the symlink without having problem with quotation, versions, path etc.
- Open Finder, locate your Sublime Text app within the Applications, in general
/Applications. - Right click on the App, then Show Package Contents.
- Navigate up to: Contents -> SharedSupport -> bin, look for
sublfile. - Copy this file
subl. - Paste the value from clipboard into terminal, it'll give you the right path to the
sublcommand already quoted, use this value to make the symlink as follows.
ln -svf {PASTE RIGHT HERE} /usr/local/bin/sublHope this can help others who might be facing the same problem.
@adrianorsouza Thank you for that, helped me after a time machine backup to a new machine.
Very helpful!
Hello, can it work on windows as well?
@Mawusi I'm not sure, it may work on Windows with a different approach here is an example: https://stackoverflow.com/a/25577833/2845262.
@adrianorsouza THank you! finally got it working. I think I also had it in .Applications and not /Applications
Xie xie ni
for all of you having trouble with this... installing wget from homebrew will automatically add subl.
thank you!
thank you!
Worked.
Thanks.
ln -svf {PASTE RIGHT HERE} /usr/local/bin/subl
It helped straight forward. Thanks!
i am getting this error ln: /usr/local/bin/subl: Permission denied
@pythonloveme since macOS High Sierra I guess, the path for /usr/local is not owned by your user, with that in mind since then you have to use sudo to operate with files within that folder or simply change the owner for your bin folder like so:
sudo chown $USER /usr/local/bin
Thanks a lot
Thanks!
This is awesome.