Support multi-word EDITOR values

When the value of EDITOR was more than one words (e.g. emacsclient -c),
it wasn't properly split in an array for subprocess.call and cheat would
fail to launch it.
This commit fixes that.

Closes #301
This commit is contained in:
Romanos Skiadas 2016-10-12 23:16:26 +03:00 committed by Chris Lane
parent 7392787e31
commit a6ec02c296
2 changed files with 14 additions and 14 deletions

View File

@ -1,9 +1,8 @@
import os
import shutil
import subprocess
from cheat import sheets
from cheat.utils import die, editor
from cheat.utils import die, open_with_editor
def copy(current_sheet_path, new_sheet_path):
""" Copies a sheet to a new path """
@ -39,22 +38,12 @@ def create_or_edit(sheet):
def create(sheet):
""" Creates a cheatsheet """
new_sheet_path = os.path.join(sheets.default_path(), sheet)
try:
subprocess.call([editor(), new_sheet_path])
except OSError:
die('Could not launch ' + editor())
open_with_editor(new_sheet_path)
def edit(sheet):
""" Opens a cheatsheet for editing """
try:
subprocess.call([editor(), path(sheet)])
except OSError:
die('Could not launch ' + editor())
open_with_editor(path(sheet))
def exists(sheet):

View File

@ -1,6 +1,7 @@
from __future__ import print_function
import os
import sys
import subprocess
def colorize(sheet_content):
@ -46,6 +47,16 @@ def editor():
return editor
def open_with_editor(filepath):
""" Open `filepath` using the EDITOR specified by the environment variables """
editor_cmd = editor().split()
try:
subprocess.call(editor_cmd + [filepath])
except OSError:
die('Could not launch ' + editor())
def warn(message):
""" Prints a message to stderr """
print((message), file=sys.stderr)