From 0e1fd56310060d269d798aadb80784651abcba0e Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 26 May 2019 16:34:05 +0200 Subject: Move edit_post_with_editor to external file --- cli/cli.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'cli') diff --git a/cli/cli.py b/cli/cli.py index 33bd1422..4c9733b1 100644 --- a/cli/cli.py +++ b/cli/cli.py @@ -1,5 +1,8 @@ #/bin/python3 +import os +import subprocess + from generators import generators @@ -13,3 +16,19 @@ def regenerate(args): """Wrapper for generate_blog(fresh=True).""" # pylint: disable=unused-argument exit(generators.generate_blog(fresh=True)) + + +def edit_post_with_editor(path): + """Launch text editor to edit post at a given path. + + Text editor is $VISUAL, then if empty, $EDITOR, then if still empty, + vi. + + """ + if "VISUAL" in os.environ: + editor = os.environ["VISUAL"] + elif "EDITOR" in os.environ: + editor = os.environ["EDITOR"] + else: + editor = "vi" + subprocess.call([editor, path]) -- cgit v1.2.1