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 <firstname.lastname@example.org> 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.