You can detect the TERM_PROGRAM
in your ~/.bashrc
or for that matter ~/.zshrc
depending on your shell:
if [ "$TERM_PROGRAM" = "vscode" ]
then
export GIT_EDITOR="code"
else
export GIT_EDITOR="emacs"
fi
Looking at man git-commit
you can see how git picks the appropriate editor, and you might want to simply set the EDITOR
environment variable instead of GIT_EDITOR
as other programs would benefit from this as well:
$ man git-commit | awk '/core.editor/' RS=
ENVIRONMENT AND CONFIGURATION VARIABLES
The editor used to edit the commit log message will be chosen from the
GIT_EDITOR environment variable, the core.editor configuration
variable, the VISUAL environment variable, or the EDITOR environment
variable (in that order). See git-var(1) for details.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…