aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2024-10-26 21:33:04 +0200
committerWolfgang Müller2024-11-06 21:30:12 +0100
commitf553ada1f4d0e1741aff828d83885caa80431f2d (patch)
treec4332c668cb774ce626b5f6d9c86668198e37578
parentef2ba0943d941b080946f85993e4383cd5e0b1a3 (diff)
downloadlater-f553ada1f4d0e1741aff828d83885caa80431f2d.tar.gz
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.
-rwxr-xr-xlater21
-rw-r--r--later.16
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.