From 7559af64953f4f43a0ab3623da7f9bc837b554a3 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Mon, 11 Jul 2016 21:06:01 +0300 Subject: [PATCH] Add default editor --- diary.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/diary.py b/diary.py index a8fe5b7..d8c49b2 100755 --- a/diary.py +++ b/diary.py @@ -17,6 +17,8 @@ EDITOR_VARIABLES = [ 'EDITOR', ] +DEFAULT_EDITOR = 'vi' + def main(): root_directory = get_root_directory() @@ -74,12 +76,9 @@ def touch_file(full_path): def get_editor(): - for editor_variable in EDITOR_VARIABLES: - editor = os.getenv(editor_variable) - if editor: - return editor - - return None + editors = [os.getenv(i) for i in EDITOR_VARIABLES] + available = [editor for editor in editors if editor] + return next(iter(available), DEFAULT_EDITOR) def check_editor(editor):