diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2021-02-12 09:39:10 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2021-02-12 09:39:10 +0100 |
commit | 02ea5f0f21809faf7c5ee99f79c5ba684ff8fba5 (patch) | |
tree | 655fc5347d0fd4317f390c1fb86f546ca93fdb5f | |
parent | 9d7addae62b057498c6d86229e993eaf2e2a10e2 (diff) |
Don't fail when vim is not set. refs: #7
-rw-r--r-- | lesana/command.py | 27 |
1 files 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: |