From f553ada1f4d0e1741aff828d83885caa80431f2d Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Sat, 26 Oct 2024 21:33:04 +0200 Subject: Allow manually deleting watch_later entries This commit introduces the "del" command which allows the user to delete watch_later entries manually. Make sure to silently ignore entries that were not found - we'll print the entire list of entries subsequently anyway. --- later | 21 +++++++++++++++++++-- later.1 | 6 ++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/later b/later index 3ffc645..5f7f1dc 100755 --- a/later +++ b/later @@ -35,6 +35,7 @@ def usage(message=""): lines.append("usage: later [options] [list]") lines.append(" [options] [add] item ...") + lines.append(" [options] del item ...") lines.append("options: [-u | --update-titles]") sys.exit("\n".join(lines)) @@ -228,6 +229,10 @@ def entries(title_map): yield WatchLaterEntry(name=name, path=entry.path, mtime=mtime) +def hexdigest(entry): + return hashlib.md5(entry.encode("utf-8")).hexdigest().upper() + + def list_entries(args, title_map): for entry in entries(title_map): print(entry.format(title_map)) @@ -235,8 +240,7 @@ def list_entries(args, title_map): def add_entries(args, title_map): for entry in args.rest: - filename = hashlib.md5(entry.encode("utf-8")).hexdigest().upper() - path = os.path.join(watch_later_dir, filename) + path = os.path.join(watch_later_dir, hexdigest(entry)) try: with open(path, "x") as handle: @@ -247,8 +251,21 @@ def add_entries(args, title_map): exit(e) +def delete_entries(args, title_map): + for entry in args.rest: + path = os.path.join(watch_later_dir, hexdigest(entry)) + + try: + os.remove(path) + except FileNotFoundError: + pass + except OSError as e: + exit(e) + + commands = { "add": Command("add", add_entries), + "del": Command("del", delete_entries), "list": Command("list", list_entries, implies_list=False, args=False), } diff --git a/later.1 b/later.1 index b9f38b4..d100ea9 100644 --- a/later.1 +++ b/later.1 @@ -12,6 +12,10 @@ .Op options .Op Ic add .Ar item ... +.Nm +.Op options +.Ic del +.Ar item ... .Sh DESCRIPTION .Nm is a program to manage watch_later entries as created by @@ -34,6 +38,8 @@ The commands are as follows: Creates watch_later entries for the given items. This command is implied if it wasn't explicitly given but there are remaining arguments. +.It Sy del Em item ... +Deletes watch_later entries matching the given items. .It Sy list Lists all watch_later entries. This command is implied if there are no remaining arguments. -- cgit v1.2.3-2-gb3c3