From 307bcc3faac98d90ef7c0ec8c42985178a3d3148 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 20 Jun 2023 09:44:35 -0400 Subject: [PATCH] Do not re-encrypt and sync if an edited note is unchanged Former-commit-id: b8bcb481830ad5deb344d4d0c79976db7f06bb52 Former-commit-id: 6ebe9ee2f25dcfd90bea3784d337cb6cefbe903e --- lib/sshyp.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index 8d8c681..d147505 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -117,14 +117,17 @@ def pass_gen(): # creates a temporary file to allow notes to be edited by standard editors -def edit_note(_note_lines): +def edit_note(_note_lines, _exit_on_match=False): from tempfile import NamedTemporaryFile + _joined_note_lines = '\n'.join(_note_lines) with NamedTemporaryFile(mode='w+') as _tmp: - _tmp.write('\n'.join(_note_lines)) + _tmp.write(_joined_note_lines) _tmp.seek(0) run((editor, _tmp.name)) _tmp.seek(0) _new_note = _tmp.read().rstrip() + if _exit_on_match and _joined_note_lines == _new_note: + s_exit(0) return _new_note @@ -483,7 +486,7 @@ def edit(): _detail, _edit_line = str(input('url: ')), 2 if arguments[2] in ('note', '-n'): _old_lines = decrypt(directory + entry_name, _quick_verify=quick_unlock_enabled) - _new_lines = _old_lines[0:3] + edit_note(_old_lines[3:]).split('\n') + _new_lines = _old_lines[0:3] + edit_note(_old_lines[3:], True).split('\n') else: _new_lines = optimized_edit(decrypt(directory + entry_name, _quick_verify=quick_unlock_enabled), _detail, _edit_line)