Compare commits

...

5 Commits
v2.10 ... v1.0

Author SHA1 Message Date
Jared Cordasco
77327f190f Added .gitattributes to allow for git archive use on releases. 2010-04-23 21:00:00 -05:00
Jared Cordasco
654c0c6d79 Merged done_functionality into git_integration. 2010-04-14 14:50:43 -05:00
Jared Cordasco
d3c14201a5 Initial version of done functionality w/ basic test. 2010-04-13 23:09:57 -05:00
Jared Cordasco
5a5f3bd24d Tab fixes. 2010-04-13 10:36:31 -05:00
Jared Cordasco
868dad6d5c First stab at git integration. 2010-01-14 01:57:18 -05:00
3 changed files with 186 additions and 26 deletions

6
.gitattributes vendored Normal file
View File

@@ -0,0 +1,6 @@
.git[ia]* export-ignore
GEN-VERSION-FILE export-ignore
Makefile export-ignore
README.textile export-ignore
VERSION-FILE export-ignore
tests export-ignore

52
tests/t1550-done.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/sh
test_description='done functionality
'
. ./test-lib.sh
#DATE=`date '+%Y-%m-%d'`
test_todo_session 'done usage' <<EOF
>>> export TODOTXT_FORCE=1
>>> todo.sh done
usage: todo.sh done "TODO ITEM"
=== 1
EOF
cat > todo.txt <<EOF
stop
remove1
remove2
remove3
remove4
EOF
test_todo_session 'basic done' <<EOF
>>> todo.sh lsa
2 remove1
3 remove2
4 remove3
5 remove4
1 stop
--
TODO: 5 of 5 tasks shown
>>> todo.sh done smell the uppercase Roses
TODO: 'smell the uppercase Roses' marked as done.
>>> todo.sh done notice the sunflowers
TODO: 'notice the sunflowers' marked as done.
>>> todo.sh lsa
2 remove1
3 remove2
4 remove3
5 remove4
1 stop
7 x 2009-02-13 notice the sunflowers
6 x 2009-02-13 smell the uppercase Roses
--
TODO: 7 of 7 tasks shown
EOF
test_done

154
todo.sh
View File

@@ -262,7 +262,7 @@ cleaninput()
action_regexp="^\(append\|app\|prepend\|prep\|replace\)$"
# Check which action we are being used in as this affects what cleaning we do
if [ `echo $action | grep -c $action_regexp` -eq 1 ]; then
if [ `echo $action | grep -c $action_regexp` -eq 1 ]; then
# These actions use sed and & as the matched string so escape it
input=`echo $input | sed 's/\&/\\\&/g'`
fi
@@ -279,6 +279,8 @@ archive()
sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
#[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed."
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: $TODO_FILE archived." $TODO_FILE $DONE_FILE
cleanup
}
@@ -380,6 +382,8 @@ TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2}
TODOTXT_FINAL_FILTER=${TODOTXT_FINAL_FILTER:-cat}
TODOTXT_GIT_ENABLED=${TODOTXT_GIT_ENABLED:-1}
TODOTXT_GIT_VERBOSE=${TODOTXT_GIT_VERBOSE:-0}
# Export all TODOTXT_* variables
export ${!TODOTXT_@}
@@ -480,14 +484,50 @@ _addto() {
input="$now $input"
fi
echo "$input" >> "$file"
[ $TODOTXT_VERBOSE -gt 0 ] && {
( [ $TODOTXT_VERBOSE -gt 0 ] || [ $TODOTXT_GIT_ENABLED -eq 1 ] ) && {
TASKNUM=$(sed -n '$ =' "$file")
BASE=$(basename "$file")
PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z])
echo "${PREFIX}: '$input' added on line $TASKNUM."
MESG="${PREFIX}: '$input' added on line $TASKNUM."
[ $TODOTXT_VERBOSE -gt 0 ] && \
echo $MESG
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "$MESG" $file
}
}
_commit() {
[ -z "$1" ] && die "Fatal Error: No commit message."
[ -z "$2" ] && die "Fatal Error: No commit files."
MESG="$(echo $1 | sed -e 's|\\n|\n|g')"
shift
FILES=$*
if [ $TODOTXT_GIT_VERBOSE -eq 0 ] ; then
( cd $TODO_DIR
for file in $FILES ; do
BASE=$(basename $file)
git add $BASE > /dev/null 2>&1
[ "$?" != 0 ] && die "Fatal Error: Git add $BASE failed."
done
git commit -m "$MESG" > /dev/null 2>&1
[ "$?" != 0 ] && die "Fatal Error: Git commit failed."
)
else
( cd $TODO_DIR
for file in $FILES ; do
BASE=$(basename $file)
git add $BASE
[ "$?" != 0 ] && die "Fatal Error: Git add $BASE failed."
done
git commit -m "$MESG"
[ "$?" != 0 ] && die "Fatal Error: Git commit failed."
)
fi
}
_list() {
local FILE="$1"
## If the file starts with a "/" use absolute path. Otherwise,
@@ -694,6 +734,9 @@ case $action in
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Appended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else
echo "TODO: Error appending task $item."
fi
@@ -702,6 +745,15 @@ case $action in
"archive" )
archive;;
"commit" )
[ -z "$2" ] && die "usage: $TODO_SH commit MESSAGE"
shift
MESG=$*
( cd $TODO_DIR
git commit -a -m "$MESG"
);;
"del" | "rm" )
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $TODO_SH del ITEM#"
@@ -729,6 +781,8 @@ case $action in
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
fi
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: '$DELETEME' deleted." $TODO_FILE
cleanup
else
echo "TODO: No tasks were deleted."
@@ -739,6 +793,8 @@ case $action in
else
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: $3 removed from $item." $TODO_FILE
fi ;;
"depri" | "dp" )
@@ -759,6 +815,8 @@ case $action in
echo "`echo "$item: $NEWTODO"`"
echo "TODO: $item deprioritized."
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: '$todo' deprioritized." $TODO_FILE
cleanup
else
die "$errmsg"
@@ -772,26 +830,28 @@ case $action in
# Split multiple do's, if comma seperated change to whitespace sepereated
# Loop the 'do' function for each item
for item in `echo $* | tr ',' ' '`; do
[ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
[ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
# Check if this item has already been done
if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then
now=`date '+%Y-%m-%d'`
# remove priority once item is done
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && {
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
echo "TODO: $item marked as done."
}
else
echo "$item is already marked done"
fi
# Check if this item has already been done
if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then
now=`date '+%Y-%m-%d'`
# remove priority once item is done
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && {
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
echo "TODO: $item marked as done."
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: '$todo' marked as done." $TODO_FILE
else
echo "$item is already marked done"
fi
done
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
@@ -799,6 +859,28 @@ case $action in
fi
cleanup ;;
"done" )
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Done: "
read input
else
[ -z "$2" ] && die "usage: $TODO_SH done \"TODO ITEM\""
shift
input=$*
fi
now=`date '+%Y-%m-%d'`
# remove priority once item is done
newtodo=$(sed -e "s/^(.) // ; s|^|&x $now |" <<<${input})
echo "$newtodo" >> "$DONE_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && {
echo "TODO: '$input' marked as done."
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: '$input' marked as done." $DONE_FILE
cleanup;;
"help" )
if [ -t 1 ] ; then # STDOUT is a TTY
if (exec which ${PAGER:-less} 2>/dev/null >/dev/null); then
@@ -863,6 +945,11 @@ case $action in
_list "$TODO_FILE" "$pri"
;;
"log" | "pull" | "push" )
( cd $TODO_DIR
git $action
);;
"move" | "mv" )
# replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $TODO_SH mv ITEM# DEST [SRC]"
@@ -897,6 +984,9 @@ case $action in
echo "$MOVEME" >> "$dest"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: '$MOVEME' moved from '$src' to '$dest'." \
$src $dest
cleanup
else
echo "TODO: No tasks moved."
@@ -937,12 +1027,15 @@ case $action in
# If priority isn't set prepend
if [ -z $priority ]; then
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
[ $TODOTXT_VERBOSE -gt 0 ] && {
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
}
else
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else
echo "TODO: Error prepending task $item."
fi
# If priority is set, remove priority, prepend and add back priority
@@ -952,9 +1045,12 @@ case $action in
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
}
else
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else
echo "TODO: Error prepending task $item."
fi
fi
fi
cleanup;;
@@ -979,6 +1075,8 @@ note: PRIORITY must be anywhere from A to Z."
echo "`echo "$item: $NEWTODO"`"
echo "TODO: $item prioritized ($newpri)."
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: $item prioritized ($newpri)." $TODO_FILE
cleanup
else
die "$errmsg"
@@ -1013,12 +1111,14 @@ note: PRIORITY must be anywhere from A to Z."
else
sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1|" "$TODO_FILE"
fi
NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
[ $TODOTXT_VERBOSE -gt 0 ] && {
NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
echo "$item: $todo"
echo "replaced with"
echo "$item: $NEWTODO"
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "$item: $todo\nreplaced with\n$item: $NEWTODO" $TODO_FILE
cleanup;;
"report" )
@@ -1037,6 +1137,8 @@ note: PRIORITY must be anywhere from A to Z."
echo ${TDONE:-0})
echo $TECHO >> "$REPORT_FILE"
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Report file updated." $REPORT_FILE
cat "$REPORT_FILE"
cleanup;;