Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to use Sublime Text 2 for editing Git commit messages. Right now I have the following in my bash rc file:

export EDITOR="sublime -nw"

This works well if Sublime is already running. But if it's not, Sublime starts up with 2 windows rather than 1: one for my Git commit message, and one with the project I was working on most recently. And before Git stops waiting for me to finish editing, I have to close both of those windows.

Is there a better way to set EDITOR which works around this problem?

share|improve this question

1 Answer 1

After posting this question on StackOverflow about a year ago (and being told the question belonged on Superuser), I have come up with a setup which works really well:

  • ~/.bin/start_sublime:

    #!/bin/bash
    # this script ensures that Sublime Text is running
    
    if [ ! "$(pidof sublime_text)" ] ; then
      # start up an instance of Sublime
      "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" &
      sleep 1 # avoid race condition
    fi
    
  • ~/.bin/sub_new_block

This opens a new window, and waits for you to close that window only, not any other Sublime window which you may have had open. This makes it work just right for editing patches or commit messages in git, etc:

    #!/bin/bash
   /home/alex/.bin/start_sublime
   "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" -nw $FILE
  • ~/.bin/sub_existing_noblock:

This uses an existing window if there is one, and the shell does not wait for you to close the window:

    #!/bin/bash
    "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" $FILE &
  • ~/.bin/sub_new_noblock:

This always opens a new window, and again the shell does not wait for you to close the window:

    #!/bin/bash
    "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" -n $FILE &

For general editing, sub_new_noblock seems to be the most useful variant, so I alias it as sub. For git, I use the following config: git config --global core.editor sub_new_block. For other programs which launch an editor, I configure them to use whichever script is most appropriate.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.