`cheat` now honors `CHEAT_EDITOR` and `VISUAL` environment variables in

addition to `EDITOR`.
This commit is contained in:
Chris Lane 2016-10-01 13:55:50 -04:00
parent 7d4150b937
commit 597acec6ac
1 changed files with 12 additions and 11 deletions

View File

@ -30,20 +30,21 @@ def die(message):
def editor():
""" Determines the user's preferred editor """
if 'EDITOR' not in os.environ:
# determine which editor to use
editor = os.environ.get('CHEAT_EDITOR') \
or os.environ.get('VISUAL') \
or os.environ.get('EDITOR') \
or False
# assert that the editor is set
if editor == False:
die(
'In order to create/edit a cheatsheet you must set your EDITOR '
'environment variable to your editor\'s path.'
'You must set a CHEAT_EDITOR, VISUAL, or EDITOR environment '
'variable in order to create/edit a cheatsheet.'
)
elif os.environ['EDITOR'] == "":
die(
'Your EDITOR environment variable is set to an empty string. It must '
'be set to your editor\'s path.'
)
else:
return os.environ['EDITOR']
return editor
def warn(message):
""" Prints a message to stderr """