Say we\'re within a Python environment, and we could be on Windows, OSX, or Linux.
How do we determine the editor that git uses?
If it was just the environment v
Run git var GIT_EDITOR
. The resulting output is the name of the editor to use, suitable to pass to a shell:
import subprocess
def git_var(what):
"return GIT_EDITOR or GIT_PAGER, for instance"
proc = subprocess.Popen(['git', 'var', what], shell=False,
stdout=subprocess.PIPE)
output = proc.stdout.read()
status = proc.wait()
if status != 0:
... raise some error ...
output = output.rstrip(b'\n')
output = output.decode('utf8', errors='ignore') # or similar for py3k
return output
(whether and how you want to stringify bytes is up to you of course).