mirror of https://github.com/cheat/cheat.git
Merge branch 'master' of https://github.com/0rax/cheat into 0rax-master
* 'master' of https://github.com/0rax/cheat: Added 1 check for EDITOR var, if EDITOR is set to "" + added try catch to catch subprocess error like EDITOR variable pointing to a non installed editor Split EDITOR variable to prevent error on popen while using EDITOR var with spaces prepare to merge Revert Print back to main, would be easier to integrate other positional option like that
This commit is contained in:
commit
545c35722a
31
cheat
31
cheat
|
@ -69,7 +69,7 @@ class CheatSheets(object):
|
||||||
if not self.dirs:
|
if not self.dirs:
|
||||||
error_msg = 'The {default} dir does not exist or the CHEATPATH var is not set.'
|
error_msg = 'The {default} dir does not exist or the CHEATPATH var is not set.'
|
||||||
print >> sys.stderr, error_msg.format(default=DEFAULT_CHEAT_DIR)
|
print >> sys.stderr, error_msg.format(default=DEFAULT_CHEAT_DIR)
|
||||||
exit()
|
exit(1)
|
||||||
self.sheets = self.__cheat_files()
|
self.sheets = self.__cheat_files()
|
||||||
|
|
||||||
def __cheat_directories(self):
|
def __cheat_directories(self):
|
||||||
|
@ -106,14 +106,21 @@ class CheatSheets(object):
|
||||||
# Assert that the EDITOR environment variable is set and that at least 3
|
# Assert that the EDITOR environment variable is set and that at least 3
|
||||||
# arguments have been given
|
# arguments have been given
|
||||||
if 'EDITOR' not in os.environ:
|
if 'EDITOR' not in os.environ:
|
||||||
print('In order to use "create" or "edit" you must set your '
|
print >> sys.stderr, ('In order to create/edit a cheatsheet you '
|
||||||
'EDITOR environment variable to your favorite editor\'s path')
|
'must set your EDITOR environment variable to your favorite '
|
||||||
exit()
|
'editor\'s path.')
|
||||||
|
exit(1)
|
||||||
|
elif os.environ['EDITOR'] == "":
|
||||||
|
print >> sys.stderr, ('Your EDITOR environment variable is set '
|
||||||
|
'to nothing, in order to create/edit a cheatsheet your must '
|
||||||
|
'set it to a valid editor\'s path.')
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
editor = os.environ['EDITOR'].split()
|
||||||
# if the cheatsheet already exists, open it for editing
|
# if the cheatsheet already exists, open it for editing
|
||||||
|
try:
|
||||||
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 +128,16 @@ 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)])
|
except OSError, e:
|
||||||
|
print >> sys.stderr, ("Could not launch `%s` as your editor : %s"
|
||||||
|
% (editor[0], e.strerror))
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
"""Lists the cheatsheets that are currently available"""
|
"""Lists the cheatsheets that are currently available"""
|
||||||
|
|
Loading…
Reference in New Issue