3 # Copyright (C) 2008 Alejandro Mery <amery@geeks.cl>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 [ $# -eq 0 ] ||
echo "ERROR: $*" >&2
24 Usage: $0 [options] [<object>]
25 ${cmd} [-t <tag>*] [<message>] - new entry
26 ${cmd} [-T|--tags] - list tags
34 echo "Ctrl-C pressed, aborting." >&2
41 options
=$
( getopt
-o "t:T" -l "tags" -- "$@" )
46 # load new arguments list
47 eval set -- "$options"
52 while [ $# -gt 0 ]; do
57 -t) TAGS
="$TAGS $2"; shift ;;
60 -*) todo_usage unknown option
"$1"
66 TAGS
=$
( echo "$TAGS" |
tr 'a-z' 'A-Z' )
72 TODOTMP
="${TMP:-/tmp}/.todo.$$"
74 # find a unique date/hash
76 while [ -z "$DATE" ]; do
77 DATE
=$
(date --rfc-3339=seconds
)
78 DATEHASH
=$
( echo "$DATE" |
sha1sum | cut
-d' ' -f1 )
79 DATEHASH_1
=$
( echo "$DATEHASH" | cut
-c 1 )
80 ENTRYDIR
="$TODODIR/entries/$DATEHASH_1"
81 ENTRY
="$ENTRYDIR/$DATEHASH"
83 if [ -e "$ENTRY" ]; then
92 echo "$*" > "$TODOTMP"
93 echo "Added: $DATE" >> "$TODOTMP"
95 echo "Subject: ..." > "$TODOTMP.empty"
96 echo "Added: $DATE" >> "$TODOTMP.empty"
97 cp "$TODOTMP.empty" "$TODOTMP"
99 ${EDITOR:-vi} "$TODOTMP"
101 if cmp -s "$TODOTMP" "$TODOTMP.empty"; then
102 rm -f "$TODOTMP" "$TODOTMP.empty"
107 mv "$TODOTMP" "$ENTRY"
109 for tag
in $TAGS INBOX
; do
110 [ -d "$TODODIR/$tag" ] || mkdir
"$TODODIR/$tag"
112 ln -s "../entries/$DATEHASH_1/$DATEHASH" "$TODODIR/$tag/$DATEHASH"
120 ls -1d "$TODODIR"/* |
sed -e "s,^$TODODIR/,," |
grep -v '^entries$'
124 new
) todo_new
"$@" ;;