about summary refs log tree commit diff stats
path: root/bash/acmetodo-add
diff options
context:
space:
mode:
Diffstat (limited to 'bash/acmetodo-add')
-rwxr-xr-xbash/acmetodo-add25
1 files changed, 25 insertions, 0 deletions
diff --git a/bash/acmetodo-add b/bash/acmetodo-add
new file mode 100755
index 0000000..b40663d
--- /dev/null
+++ b/bash/acmetodo-add
@@ -0,0 +1,25 @@
+#!/bin/sh
+# acmetodo-add: Adds a new todo item.
+
+PLAN9=${PLAN9:-"/usr/local/plan9"}
+TODO_FILE="$PLAN9/lib/todo"
+ACME_BIN="$PLAN9/bin/acme"
+
+# Prompt for subject in Acme's current window (where the command was issued)
+# Output to stderr so it doesn't interfere with potential stdout pipe.
+echo -n "Subject: " >/dev/stderr
+read subject
+
+if [ -n "$subject" ]; then
+    echo "[ ] $subject" >> "$TODO_FILE"
+    # Find the winid of the main acmetodo window to refresh it.
+    # This assumes the main acmetodo window's name is the TODO_FILE path.
+    MAIN_TODO_WINID=$($ACME_BIN -w | grep "^$TODO_FILE" | cut -d' ' -f1 | head -n 1)
+    if [ -n "$MAIN_TODO_WINID" ]; then
+        echo 'Get' | $ACME_BIN -a "$MAIN_TODO_WINID"
+    else
+        echo "Warning: Main acmetodo window not found to refresh." >/dev/stderr
+    fi
+else
+    echo "No subject provided. Item not added." >/dev/stderr
+fi
\ No newline at end of file