Compare commits

..

3 Commits
v1.0.0 ... v2.6

Author SHA1 Message Date
Yujie Wu
2a65615c7a Added a case for the fixed replace command. 2010-05-08 08:52:59 +08:00
Yujie Wu
d7e194b09d Fixed bug for replace command. 2010-05-08 08:52:59 +08:00
Jared Cordasco
a4ab8a808a Tab fixes. 2010-04-16 06:12:00 +08:00
4 changed files with 13 additions and 168 deletions

6
.gitattributes vendored
View File

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

View File

@@ -71,6 +71,11 @@ TODO: 4 prioritized (A).
4: (A) collect the eggs
replaced with
4: (A) collect the bread
>>> todo.sh replace 4 collect the eggs
4: (A) collect the bread
replaced with
4: (A) collect the eggs
EOF
test_todo_session 'replace with &' << EOF
>>> todo.sh replace 3 "thrash the hay & thresh the wheat"

View File

@@ -1,52 +0,0 @@
#!/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

118
todo.sh
View File

@@ -279,8 +279,6 @@ 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
}
@@ -382,8 +380,6 @@ 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_@}
@@ -484,50 +480,14 @@ _addto() {
input="$now $input"
fi
echo "$input" >> "$file"
( [ $TODOTXT_VERBOSE -gt 0 ] || [ $TODOTXT_GIT_ENABLED -eq 1 ] ) && {
[ $TODOTXT_VERBOSE -gt 0 ] && {
TASKNUM=$(sed -n '$ =' "$file")
BASE=$(basename "$file")
PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z])
MESG="${PREFIX}: '$input' added on line $TASKNUM."
[ $TODOTXT_VERBOSE -gt 0 ] && \
echo $MESG
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "$MESG" $file
echo "${PREFIX}: '$input' added on line $TASKNUM."
}
}
_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,
@@ -734,9 +694,6 @@ 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
@@ -745,15 +702,6 @@ 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#"
@@ -781,8 +729,6 @@ 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."
@@ -793,8 +739,6 @@ 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" )
@@ -815,8 +759,6 @@ 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"
@@ -847,8 +789,6 @@ case $action in
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
@@ -859,28 +799,6 @@ 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
@@ -945,11 +863,6 @@ 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]"
@@ -984,9 +897,6 @@ 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."
@@ -1027,15 +937,12 @@ 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"
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else
else
echo "TODO: Error prepending task $item."
fi
# If priority is set, remove priority, prepend and add back priority
@@ -1045,12 +952,9 @@ case $action in
newtodo=$(sed "$item!d" "$TODO_FILE")
echo "$item: $newtodo"
}
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
$TODO_FILE
else
else
echo "TODO: Error prepending task $item."
fi
fi
fi
cleanup;;
@@ -1075,8 +979,6 @@ 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"
@@ -1109,16 +1011,14 @@ note: PRIORITY must be anywhere from A to Z."
if [ -z $priority ]; then
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
else
sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1|" "$TODO_FILE"
sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $input|" "$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" )
@@ -1137,8 +1037,6 @@ 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;;