Blob


1 #!/bin/sh
3 set -o pipefail
4 program=$(basename "$0")
5 fail() { echo "$1"; exit 1; }
7 for f in *; do
8 expr "$f" : [Tt][Oo][Dd][Oo] > /dev/null && todo_file="$f" && break
9 done
11 [ -n $todo_file ] || todo_file="${TODO_FILE:-${PWD}/TODO}"
13 todo_alt_file="${TODO_ALT_FILE:-${PWD}/REMEMBER}"
14 done_file="${DONE_FILE:-${PWD}/DONE}"
16 usage() {
17 echo "usage: $program TASK"
18 echo " $program [-d LINENUM] [-e] [-Ss QUERY]"
19 }
21 # t_done(int)
22 t_done() {
23 int=$1
24 tmpfile=$(mktemp)
25 sed -n "${int}!p" "$todo_file" > "$tmpfile"
26 mv "$todo_file" "${todo_file}~"
27 mv "$tmpfile" "$todo_file"
28 }
30 t_print() {
31 lines=$(wc -l < "$todo_file")
32 width=$(echo $lines | wc -c)
33 nl -s' ' -w"$width" "$todo_file"
34 }
36 main() {
37 if getopts hed:S:s: opt; then
38 case "$opt" in
39 (e) $EDITOR "$todo_file"
40 exit ;;
41 (d) t_done "$OPTARG"
42 exit ;;
43 (S) t_print | grep -iw "$OPTARG"
44 exit ;;
45 (s) t_print | grep -i "$OPTARG"
46 exit ;;
47 (h) usage
48 exit ;;
49 (?) usage
50 exit 1 ;;
51 esac
52 elif test -n "$1"; then
53 echo "$@" >> "$todo_file"
54 else
55 t_print
56 fi
57 }
59 main "$@"