Split EDITOR variable to prevent error on popen while using EDITOR var with spaces

This commit is contained in:
0rax 2013-09-20 02:12:48 +02:00
parent 42642526f8
commit 72b7af171d
1 changed files with 5 additions and 7 deletions

12
cheat
View File

@ -109,11 +109,11 @@ class CheatSheets(object):
print('In order to use "create" or "edit" you must set your ' print('In order to use "create" or "edit" you must set your '
'EDITOR environment variable to your favorite editor\'s path') 'EDITOR environment variable to your favorite editor\'s path')
exit() exit()
else:
editor = os.environ['EDITOR'].split()
# if the cheatsheet already exists, open it for editing # if the cheatsheet already exists, open it for editing
if cheat in sheets.sheets: if cheat in sheets.sheets:
subprocess.call([os.environ['EDITOR'], subprocess.call(editor + [os.path.join(self.sheets[cheat], cheat)])
os.path.join(self.sheets[cheat], cheat)])
# otherwise, create it # otherwise, create it
else: else:
@ -121,14 +121,12 @@ class CheatSheets(object):
# Attempt to write the new cheatsheet to the user's ~/.cheat dir if it # Attempt to write the new cheatsheet to the user's ~/.cheat dir if it
# exists. If it does not exist, attempt to create it. # exists. If it does not exist, attempt to create it.
if os.access(DEFAULT_CHEAT_DIR, os.W_OK) or os.makedirs(DEFAULT_CHEAT_DIR): if os.access(DEFAULT_CHEAT_DIR, os.W_OK) or os.makedirs(DEFAULT_CHEAT_DIR):
subprocess.call([os.environ['EDITOR'], subprocess.call(editor + [os.path.join(DEFAULT_CHEAT_DIR, cheat)])
os.path.join(DEFAULT_CHEAT_DIR, cheat)])
# If the directory cannot be created, write to the python package # If the directory cannot be created, write to the python package
# directory, though that will likely require the use of sudo # directory, though that will likely require the use of sudo
else: else:
subprocess.call([os.environ['EDITOR'], subprocess.call(editor + [os.path.join(cs.cheat_dir, cheat)])
os.path.join(cs.cheat_dir, cheat)])
def list(self): def list(self):
"""Lists the cheatsheets that are currently available""" """Lists the cheatsheets that are currently available"""