From 860d16f0c8ef2400e8649c8af5df2324bc7fbb09 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Thu, 14 Sep 2023 13:37:13 +0200 Subject: [PATCH] python tool: open note if only one match --- cli/python/app.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/python/app.py b/cli/python/app.py index b50fad8..dc8e55d 100644 --- a/cli/python/app.py +++ b/cli/python/app.py @@ -7,12 +7,12 @@ import sys import time def listnotes(filter = ""): - cnt = 0 + matching = [] for i in reversed(range(len(data))): if filter in data[i]["title"]: print("[" + str(i) + "]", data[i]["title"]) - cnt += 1 - return cnt + matching.append(data[i]) + return matching def readtextfile(path): with io.open(path, mode = "r", encoding = "utf-8") as f: @@ -100,7 +100,8 @@ while not (command == "quit" or command == "exit" or command == "q"): elif note: editnote(note) else: - if listnotes(command) == 0: + matching = listnotes(command) + if len(matching) == 0: if ask("create '" + command + "'? "): note = { "title": command, @@ -108,5 +109,7 @@ while not (command == "quit" or command == "exit" or command == "q"): } data.insert(0, note) editnote(note) + elif len(matching) == 1: + editnote(matching.pop()) command = input("> ")