Ad

Friday, February 20, 2015

Repost Launch Sublime Text Editor from Mac Command Line

Developer Shortcut Launch Sublime Text Editor or Open Files with Sublime from the Command Line on Mac (Repost from Udacity)

Love your Sublime and want to use it to open files right from the terminal? Follow the steps below. Better yet, it helps you set 'subl' as your shortcut, punch in subl <filename> to open text / code files with sublime right from the command line. Save you a few words of typing too - somewhat important for a lot of developers.

Launching Sublime from command-line

source: udacity learning wiki! Not written by me. I just need it so often, I am keeping the entire notes here.

Windows

  1. Find the directory where Sublime is located for you.  For many people, this is C:/Program\ Files/Sublime\ Text\ 2/sublime_text.exe.  To test this, run ls C:/Program\ Files/Sublime\ Text\ 2 within Git Bash.  You should see sublime_text.exe listed.  If you get the errorNo such file or directory, Sublime is located somewhere else for you and you'll need to find it.  For example, it might be under C:/Program\ Files\ (x86)`.
  2. Run the following command in Git Bash: echo 'alias subl="C:/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.bashrc If sublwas in a different directory for you in step 1, use that directory.
  3. Close and re-open Git Bash.  Typing subl in Git Bash should now open Sublime.

Mac

  1. Find where the subl command is located.
    subl comes with Sublime, so it should be in the directory where Sublime is located for you.  For many people, this is/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin.  To test this, runls /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin.  You should see the subl command listed.  If you get the errorNo such file or directory, Sublime is located somewhere else for you and you'll need to find it.
  2. If you do not have a file named .bash_profile in your home directory, create it.  Because the name of this file begins with a period, it will not appear in most file navigators or when you run ls.  Instead, run ls -a to see if you have the file.
  3. Add the line export PATH=$PATH:/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin to the end of your .bash_profile.  If sublwas in a different directory for you in step 1, use that directory.
  4. Close and re-open your terminal.  Typing subl in the terminal should now open Sublime.
Alternatively, you can create a symbolic link to Sublime.
  1. Find where the subl command is located.
    subl comes with Sublime, so it should be in the directory where Sublime is located for you.  For many people, this is/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin.  To test this, runls /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin.  You should see the subl command listed.  If you get the errorNo such file or directory, Sublime is located somewhere else for you and you'll need to find it.
  2. If you do not have a file named .bash_profile in your home directory, create it.  Because the name of this file begins with a period, it will not appear in most file navigators or when you run ls.  Instead, run ls -a to see if you have the file.
  3. Add the lines export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH and export EDITOR='subl -w' to the end of your .bash_profile. 
  4. Save and exit .bash_profile.
  5. At the terminal command prompt type: source ~/.bash_profile
  6. At the terminal command prompt type: sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl Note that if subl was in a different directory for you in step 1, use the path to that directory. If prompted for a password, use the same password you use to log into your Mac account.
  7. Close and re-open your terminal.  Typing subl in the terminal should now open Sublime.

No comments:

Post a Comment