1

Is setting the EDITOR environment variable to : to mean no-op supported behavior in Unix? Or is it special to Git?

I stumbled across this example of passing EDITOR=: to Git to short-circuit any attempt to launch an editor:

# Amend the commit, reusing the commit message
EDITOR=: git commit --amend

But hang on a sec. Why does that work? The EDITOR environment variable should be set to point to an editor executable in your PATH, like EDITOR=vim and such. After doing some digging, I've found that Git explicitly checks the editor value against : and does not launch an editor in that case. (See commit.c for the gory details.)

So to get back to the question, it seems Git supports : as a no-op editor, and it does this by special-casing. Is : even a legal value for EDITOR, or something of a convention supported by some programs? (An alternative would be to set EDITOR=echo or EDITOR=touch so that the editor is invoked as touch FILE, leaving FILE unmodified.)

Bonus

Using : to mean no-op for EDITOR seems oddly similar to how the : Bash builtin is the no-op command equivalent to true. Coincidence?

What is the use case of noop [:] in bash?

Community
  • 1
  • 1
mxxk
  • 9,514
  • 5
  • 38
  • 46

1 Answers1

1

The use of : is likely a nod to Bourne shells (more reading on that), but as you note it is explicitly handled in Git. I don't know of anywhere documenting EDITOR=: as something that is expected to work globally.

Git support for EDITOR=: dates all the way back to 2007: https://github.com/git/git/commit/943316e96ca2dad67086af2f945e42467a27ddd6!

Community
  • 1
  • 1
dahlbyk
  • 75,175
  • 8
  • 100
  • 122