For a little while, I’ve been using emacs as my git editor because I strongly feel that vi is something that should happen to other people. It’s been fine but not everyone loves emacs or likes the debris it leaves in its wake. So I thought I’d try out TextEdit instead.
After a little testing of approaches, I first tried out this:
git config --global core.editor /Applications/TextEdit.app/Contents/MacOS/TextEdit
I picked this rather than some of the other approaches because it’s straightforward in launching the app. There’s one problem though, which is that git doesn’t pick up on the fact that a file has been edited and closed when the application remains active:
% git commit --amend hint: Waiting for your editor to close the file... (...waits forever...)
The commit completes and works when I quit TextEdit but I don’t like to quit the app each time I update a commit, especially if I have other files open. The amended commit does complete on quit:
% git commit --amend [master 59a0934] Testing TextEdit! Author: erica <email@example.com> Date: Thu Jul 12 08:02:26 2018 -0600 1 file changed, 3 insertions(+), 1 deletion(-)
So I changed my approach. I turned to
git config --global core.editor "open -W -n"
open‘s natural environmental editor for text. You don’t have to specify more than
open for git to work with the right editor.
This approach uses two tweaks. When you launch an app with
-n flag instructs
open to launch a new instance of the application even if one is already running. You may see two “TextEdit” icons open in your dock, for example.
-W and you have a slightly better solution. The
-W “wait” flag tells
open to keep waiting until the launched application has finished running. This allows
git to to wait “for your editor to close the file”, which you do by quitting TextEdit. Sure, I’d much prefer that TextEdit run using a “single file” mode, but this isn’t a bad solution.
Sadly, I couldn’t find any undocumented launch flags to make TextEdit run in single file mode and while it’s easy enough to write a Mac app that edits a single file at a time and quits on closing, it’s not a practical solution for everyone.
Is there a way to automatically propagate “done” back to git without ending a TextEdit process? I couldn’t find one. If you have a better idea, please let me know.
Well, I’m fine with vi myself but, on the other hand, I found that SourceTree turns git from a barely usable excuse for a source code control system into a really nice tool
I even use ST now that Xcode has a nice git UI. It’s a great macOS app and a great Mac app citizen.
I use BBEdit as git’s editor, through the command line tools for BBEdit. It propagates “done” back to git when you close the document.
You can also use Xcode instead of TextEdit: “xed -w”
… and I think a similar approach is possible with Sublime throught the command line launcher.
While I love SublimeText for all my non Xcode needs, for command line commit messages I use pico/nano and have for years. Its very simple & easy to use, and available on any Mac.
SourceTree is a very nice GUI to git and hg.
I use TextMate v2 – it comes with a command line launcher (“mate”). When the mate command is symlinked to mate_wait (or actually anything with _wait at the end), it will wait until you close the file before it returns control to the environment it was called from.