about summary refs log tree commit diff stats
path: root/bash/acmetodo-filter
blob: 6149207518d4d4b0d31b9a8637e0d21b9d3df5f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
# acmetodo-todo: Filters the todo list to show only 'to-do' items.

PLAN9=${PLAN9:-"/usr/local/plan9"}
TODO_FILE="$PLAN9/lib/todo"
ACME_BIN="$PLAN9/bin/acme"

# Find the winid of the main acmetodo window
MAIN_TODO_WINID=$($ACME_BIN -w | grep "^$TODO_FILE" | cut -d' ' -f1 | head -n 1)

if [ -z "$MAIN_TODO_WINID" ]; then
    echo "Error: Main acmetodo window not found." >/dev/stderr
    exit 1
fi

# Filter the content and send it back to the window
filtered_content=$(grep '^[ ] ' "$TODO_FILE")

# Clear current window content and then write the filtered content
echo 'data' | $ACME_BIN -a "$MAIN_TODO_WINID"
echo "$filtered_content" | $ACME_BIN -a "$MAIN_TODO_WINID"
echo 'clean' | $ACME_BIN -a "$MAIN_TODO_WINID" # Mark window as clean after update