From 02ea5f0f21809faf7c5ee99f79c5ba684ff8fba5 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 12 Feb 2021 09:39:10 +0100 Subject: Don't fail when vim is not set. refs: #7 --- lesana/command.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lesana/command.py b/lesana/command.py index b25fb3d..9c27eca 100644 --- a/lesana/command.py +++ b/lesana/command.py @@ -11,21 +11,22 @@ from . import Collection, Entry, TemplatingError def edit_file_in_external_editor(filepath): # First we try to use $EDITOR - try: - editor = os.environ['EDITOR'] - subprocess.call([editor, filepath]) - except FileNotFoundError as e: - if editor in str(e): - logging.info( - 'Could not open file {} with $EDITOR (currently {})'.format( - filepath, editor + editor = os.environ.get('EDITOR') + if editor: + try: + subprocess.call([editor, filepath]) + except FileNotFoundError as e: + if editor in str(e): + logging.info( + 'Could not open file {} with $EDITOR (currently {})'.format( + filepath, editor + ) ) - ) + else: + logging.warning("Could not open file {}".format(filepath)) + return False else: - logging.warning("Could not open file {}".format(filepath)) - return False - else: - return True + return True # then we try to use sensible-editor (which should be available on # debian and derivatives) try: -- cgit v1.2.3