mirror of
https://github.com/cheat/cheat.git
synced 2024-11-23 22:41:35 +01:00
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:
parent
352a760561
commit
8b3b997025
@ -1,9 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
|
||||||
|
|
||||||
from cheat import sheets
|
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):
|
def copy(current_sheet_path, new_sheet_path):
|
||||||
""" Copies a sheet to a new path """
|
""" Copies a sheet to a new path """
|
||||||
@ -39,22 +38,12 @@ def create_or_edit(sheet):
|
|||||||
def create(sheet):
|
def create(sheet):
|
||||||
""" Creates a cheatsheet """
|
""" Creates a cheatsheet """
|
||||||
new_sheet_path = os.path.join(sheets.default_path(), sheet)
|
new_sheet_path = os.path.join(sheets.default_path(), sheet)
|
||||||
|
open_with_editor(new_sheet_path)
|
||||||
try:
|
|
||||||
subprocess.call([editor(), new_sheet_path])
|
|
||||||
|
|
||||||
except OSError:
|
|
||||||
die('Could not launch ' + editor())
|
|
||||||
|
|
||||||
|
|
||||||
def edit(sheet):
|
def edit(sheet):
|
||||||
""" Opens a cheatsheet for editing """
|
""" Opens a cheatsheet for editing """
|
||||||
|
open_with_editor(path(sheet))
|
||||||
try:
|
|
||||||
subprocess.call([editor(), path(sheet)])
|
|
||||||
|
|
||||||
except OSError:
|
|
||||||
die('Could not launch ' + editor())
|
|
||||||
|
|
||||||
|
|
||||||
def exists(sheet):
|
def exists(sheet):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def colorize(sheet_content):
|
def colorize(sheet_content):
|
||||||
@ -46,6 +47,16 @@ def editor():
|
|||||||
|
|
||||||
return 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):
|
def warn(message):
|
||||||
""" Prints a message to stderr """
|
""" Prints a message to stderr """
|
||||||
print((message), file=sys.stderr)
|
print((message), file=sys.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user