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/>.
20 [ $# -eq 0 ] ||
echo "ERROR: $*" >&2
21 echo "Usage: $0 [-t tag]* [message]" >&2
28 echo "Ctrl-C pressed, aborting." >&2
35 options
=$
( getopt
-o "t:" -- "$@" )
40 # load new arguments list
41 eval set -- "$options"
46 while [ $# -gt 0 ]; do
48 -t) TAGS
="$TAGS $2"; shift ;;
51 -*) todo_usage unknown option
"$1"
57 TAGS
=$
( echo "$TAGS" |
tr 'a-z' 'A-Z' )
63 TODOTMP
="${TMP:-/tmp}/.todo.$$"
65 # find a unique date/hash
67 while [ -z "$DATE" ]; do
68 DATE
=$
(date --rfc-3339=seconds
)
69 DATEHASH
=$
( echo "$DATE" |
sha1sum | cut
-d' ' -f1 )
70 DATEHASH_1
=$
( echo "$DATEHASH" | cut
-c 1 )
71 ENTRYDIR
="$TODODIR/entries/$DATEHASH_1"
72 ENTRY
="$ENTRYDIR/$DATEHASH"
74 if [ -e "$ENTRY" ]; then
83 echo "$*" > "$TODOTMP"
84 echo "Added: $DATE" >> "$TODOTMP"
86 echo "Subject: ..." > "$TODOTMP.empty"
87 echo "Added: $DATE" >> "$TODOTMP.empty"
88 cp "$TODOTMP.empty" "$TODOTMP"
90 ${EDITOR:-vi} "$TODOTMP"
92 if cmp -s "$TODOTMP" "$TODOTMP.empty"; then
93 rm -f "$TODOTMP" "$TODOTMP.empty"
98 mv "$TODOTMP" "$ENTRY"
100 for tag
in $TAGS INBOX
; do
101 [ -d "$TODODIR/$tag" ] || mkdir
"$TODODIR/$tag"
103 ln -s "../entries/$DATEHASH_1/$DATEHASH" "$TODODIR/$tag/$DATEHASH"