launch sublime text 3 in terminal with zsh
Asked Answered
D

5

5

I recently purchased a new MacBook and I am trying to re-configure my system.

The app is inside the Applications folder as 'Sublime Text.app'

I have edited the sublime.plugin.zsh file via other advice I found online to 'Sublime Text 3.app' as well as 'Sublime Text.app' with no luck on either:

elif  [[ $('uname') == 'Darwin' ]]; then
local _sublime_darwin_paths > /dev/null 2>&1
_sublime_darwin_paths=(
    "/usr/local/bin/subl"
    "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
    "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
    "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
    "$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
    "$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
    "$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
)

for _sublime_path in $_sublime_darwin_paths; do
    if [[ -a $_sublime_path ]]; then
        alias subl="'$_sublime_path'"
        alias st=subl
        break
    fi
done
fi

alias stt='st .'

I still get

zsh: command not found: st

I am simply at a loss on where to go next

Ducks answered 10/8, 2014 at 21:22 Comment(1)
Does apropos sublime turn up anything useful?Hegyera
E
5

First, try to first launch the sublime binary manually (interactively) via zsh.

To do that, you'll have to discover where this binary is. There are two practical options here, choose what you are most comfortable with:

  1. Check manually those listed binaries, see which of them exist.
  2. Slightly modify your script to echo something inside your if:

    if [[ -a $_sublime_path ]]; then
        echo "Sublime found: $_sublime_path"
        alias subl="'$_sublime_path'"
        alias st=subl
        break
    fi
    

After finding the correct one, create the st alias in your .zshrc file:

alias st="/correct/path/to/subl"

If you don't find anything in the first step, then your original script is really not supposed to work.

Elkin answered 10/8, 2014 at 21:52 Comment(0)
K
15

I had the same problem with zsh and this did the job:

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

Then you launch a open a file my_file.txt with Sublime:

subl ./my_file.txt

Don't specify any file if you just want to open Sublime. I hope this helps ;)

Khiva answered 11/2, 2020 at 16:36 Comment(0)
E
5

First, try to first launch the sublime binary manually (interactively) via zsh.

To do that, you'll have to discover where this binary is. There are two practical options here, choose what you are most comfortable with:

  1. Check manually those listed binaries, see which of them exist.
  2. Slightly modify your script to echo something inside your if:

    if [[ -a $_sublime_path ]]; then
        echo "Sublime found: $_sublime_path"
        alias subl="'$_sublime_path'"
        alias st=subl
        break
    fi
    

After finding the correct one, create the st alias in your .zshrc file:

alias st="/correct/path/to/subl"

If you don't find anything in the first step, then your original script is really not supposed to work.

Elkin answered 10/8, 2014 at 21:52 Comment(0)
D
2

To setup alias for mac users;

open ~/.zshrc using the below command

vi ~/.zshrc

Add the following alias

alias subl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"

run subl . command should work properly.

Deportation answered 13/1, 2022 at 7:48 Comment(0)
S
1
  1. Just moved to App in mac
  2. Check your current path
echo $PATH
  1. Add a sym link from Sublime App to one of your path. Choose /usr/local/bin for example
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime 
  1. Then back to terminal and run sublime. You should be open the sublime through terminal
Squirmy answered 14/4, 2021 at 23:22 Comment(0)
D
0

Official documentation: https://www.sublimetext.com/docs/command_line.html#mac

ZSH
If using Zsh, the default starting with macOS 10.15, the following command will add the bin folder to the PATH environment variable:
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile

Dorinda answered 20/2, 2023 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.