Is it possible to know which editor git is going to use programmatically? Something like this is possible?
$git which editor
Basically, I wanted to invoke a custom editor only for git commit messages. So if file name is '.git/COMMIT_EDITMSG', I will invoke something else, otherwise I want to fallback to default git editor.
I know that git uses
$EDITOR in order to choose an editor. But all of these are not present, I don't know what to do. Here it says, it uses
vi. But in my machine, it uses
nano. Hence, it is not really reliable to hardcode that.
Hence, how to know which editor will git use programmatically? If not directly from git, is there any other workaround?
Use the command
git var GIT_EDITOR
It outputs the value using exactly that algorithm that Git would use to call an editor regardless of the way an editor is configured. If none of the
$EDITOR are set it outputs some sensible default.
When nothing is set on my Debian Linux system it outputs
/usr/bin/editor is an (indirect) symlink to
vim.gtk3. On your system the chain of symlinks is probably pointed to
If you want to run "the same editor Git would call" to edit a file
filename run this:
`git var GIT_EDITOR` filename
$(git var GIT_EDITOR) filename