summaryrefslogtreecommitdiff
path: root/todo
blob: 9e8ead0b4533c05ff045522c201ea2024e07492e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

# Write/remove a task to do later.
# Select an existing entry to remove it from the file, or type a new entry to
# add it.

file="$HOME/.local/opt/todo"
touch "$file"
height="$(wc -l "$file" | awk '{print $1}')"
prompt="Add/delete a task: "

cmd=$(dmenu -l "$height" -p "$prompt" "$@" <"$file")
while [ -n "$cmd" ]; do
	if grep -q "^$cmd\$" "$file"; then
		grep -v "^$cmd\$" "$file" >"$file.$$"
		mv "$file.$$" "$file"
		height=$((height - 1))
	else
		echo "$cmd" >>"$file"
		height=$((height + 1))
	fi

	cmd=$(dmenu -l "$height" -p "$prompt" "$@" <"$file")
done

exit 0