Home > front end >  How to open most recent SublimeText from command line with zsh?
How to open most recent SublimeText from command line with zsh?

Time:09-21

I'm having issues opening up sublime from my terminal. I've tried a lot of different methods such as watching YouTube videos or reading similar posts from this website and other blogs. However, from my research alone, it seems that the solutions I've read are from several years back. I want to use the command "subl" to automatically open up files from my command line but I keep hitting roadblocks.

So far, here is some of the info and methods that I have have tried out:

First:

echo $Shell 
returns : /bin/zsh

Second:

(I dragged the application from finder and dropped it into to terminal to figure out where it was located and this is what it returned)

returned: /Applications/Sublime\ Tex\ 3.apps

Third:

cd ~
ls -A
open .zshrc

(this is what it says when the text window opens up)

`export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Fourth:

I tried using this command line for .zsh shell from sublime website

echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile

returned : 
 permission denied: /Applications/Sublime Text 3.app

Fifth:

 ln -s "/Applications/Sublime\ Text\ 3.app" /usr/local/bin/subl
returns:
ln: /usr/local/bin/subl: File exist
subl
zsh: command not found: subl

Sixth

echo $PATH
returns:
/usr/local/opt/python/libexec/bin:/Applications/Sublime Text.app/Contents/SharedSupport/bin:/Applications/Sublime Text.app/Contents/SharedSupport/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

Afterwards proceeded to paste this code from online source:

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

returns : 
ln: /usr/local/bin/subl: File exists

In the end, nothing that I have tried works. Even when I open my terminal and type

subl
returns:
zsh: command not found: subl

or

subl hello.py 
zsh: command not found: subl

or

subl --version 
zsh: command not found: sublime

What is it that I'm doing wrong?

CodePudding user response:

I have never used SublimeText before, but I was able to get it to work immediately, by doing this:

  1. Make sure you have Homebrew installed.
  2. On the command line, run
    brew install --cask sublime-text
    
  3. Done. That's all there is to it.

Now you can type

subl .zshrc

and it will open your .zshrc file in SublimeText.

CodePudding user response:

First, you need the most up-to-date version of Sublime Text. Go to https://www.sublimetext.com/download and click on the macOS link at the very top. Unzip the downloaded file, which should happen automatically when you double-click on it, and move Sublime Text.app (you may just see it as Sublime Text in Finder) to Applications. If you get a warning about replacing files, make sure you click the Replace button.

Now, go to Terminal and enter:

sudo rm -rf /usr/local/bin/subl

You'll have to enter your password. Next, enter:

sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

and you should be all set.

  • Related