diff options
-rwxr-xr-x | later | 21 | ||||
-rw-r--r-- | later.1 | 6 |
2 files changed, 25 insertions, 2 deletions
@@ -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), } @@ -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. |