Skip to content

Commit 15a4cd5

Browse files
Issue #162: make blurb sophisticated about EDITOR. (#206)
EDITOR might contain spaces. If it does, is that just a path with spaces? Or is it a command-line with arguments? blurb now handles all these cases.
1 parent 6508f25 commit 15a4cd5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

blurb/blurb.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import math
5555
import os
5656
import re
57+
import shlex
5758
import shutil
5859
import subprocess
5960
import sys
@@ -893,8 +894,21 @@ def init_tmp_with_template():
893894

894895
init_tmp_with_template()
895896

897+
# We need to be clever about EDITOR.
898+
# On the one hand, it might be a legitimate path to an
899+
# executable containing spaces.
900+
# On the other hand, it might be a partial command-line
901+
# with options.
902+
if shutil.which(editor):
903+
args = [editor]
904+
else:
905+
args = list(shlex.split(editor))
906+
if not shutil.which(args[0]):
907+
sys.exit("Invalid GIT_EDITOR / EDITOR value: {}".format(editor))
908+
args.append(tmp_path)
909+
896910
while True:
897-
subprocess.run([editor, tmp_path])
911+
subprocess.run(args)
898912

899913
failure = None
900914
blurb = Blurbs()

0 commit comments

Comments
 (0)