I know this is ancient, but I need to do this at the end of a git helper script (alias that creates aliases from a template), and found what I think is the real answer:
There is a porcelain-ish helper called git-sh-setup
that, when sourced, gives you a git_editor
function that
runs an editor of user’s choice (GIT_EDITOR, core.editor, VISUAL or EDITOR) on a given file, but error out if no editor is specified and the terminal is dumb.
The git-sh-setup
documentation description basically tells you not to use it, and that's probably good advice in this case.
Fortunately, the git-sh-setup
is a shell script and the git_editor
portion of it is pretty small, and we can just copy that:
git_editor() {
if test -z "${GIT_EDITOR:+set}"
then
GIT_EDITOR="$(git var GIT_EDITOR)" || return $?
fi
eval "$GIT_EDITOR" '"$@"'
}
You should be able to put that in your own scripts or turn it into a bash alias and then call it like git_editor file1.txt file2.txt ...