From 38995d245633a6c250c0194f79f04bfeed3e5f03 Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Sun, 7 Jun 2026 08:50:31 -0500 Subject: [PATCH] Listall --- plugins/labels.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/labels.py b/plugins/labels.py index b23cfc4..612fab1 100644 --- a/plugins/labels.py +++ b/plugins/labels.py @@ -62,7 +62,8 @@ action_map = { "removeall": 2, "show": 3, "transfer": 4, - "edit": 5 + "edit": 5, + "listall": 6, } def modify_labels(lib, opts, args): @@ -86,6 +87,10 @@ def modify_labels(lib, opts, args): edit_labels(lib, opts, args[1:]) return + if actnum == 6: # listall + listall_labels(lib, opts, args[1:]) + return + if actnum >= 2: label = None query = args[1:] @@ -104,6 +109,15 @@ def modify_labels(lib, opts, args): else: do_modify_labels(lib, items, label, actnum) +def listall_labels(lib, opts, args): + """Print every distinct label key used across all items.""" + all_labels = set() + for item in lib.items(): + if LABELS_FIELD_NAME in item and item[LABELS_FIELD_NAME]: + all_labels.update(item[LABELS_FIELD_NAME].keys()) + for label in sorted(all_labels): + print_(label) + def transfer_labels(lib, opts, args): source_query = args[0] dest_query = args[1] @@ -343,7 +357,8 @@ Actions: show [query] Display labels on items transfer Copy labels from one item to another - edit [query] Open items' labels in a text editor""" + edit [query] Open items' labels in a text editor + listall List all label keys used in the library""" labels_command.func = modify_labels class HasLabelQuery(FieldQuery):