From aed06503c4290026c43a8559d8e1fdddc6b46f67 Mon Sep 17 00:00:00 2001 From: Honnix Date: Fri, 2 Dec 2022 09:36:43 +0100 Subject: [PATCH] Add a flag whether to read file It is not always intended to read the file back, so adding a flag so users can decide. --- editor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/editor.py b/editor.py index 39cc942..712a532 100755 --- a/editor.py +++ b/editor.py @@ -85,7 +85,7 @@ def get_tty_filename(): return '/dev/tty' -def edit(filename=None, contents=None, use_tty=None, suffix=''): +def edit(filename=None, contents=None, use_tty=None, suffix='', read_file=True): editor = get_editor() args = [editor] + get_editor_args(os.path.basename(os.path.realpath(editor))) @@ -113,8 +113,9 @@ def edit(filename=None, contents=None, use_tty=None, suffix=''): proc = subprocess.Popen(args, close_fds=True, stdout=stdout) proc.communicate() - with open(filename, mode='rb') as f: - return f.read() + if read_file: + with open(filename, mode='rb') as f: + return f.read() def _get_editor(ns):