Merged done_functionality into git_integration.
This commit is contained in:
52
tests/t1550-done.sh
Executable file
52
tests/t1550-done.sh
Executable 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
|
||||||
@@ -18,7 +18,7 @@ cat /dev/null > $HOME/todo.txt
|
|||||||
|
|
||||||
# Run replace
|
# Run replace
|
||||||
"$HOME/bin/todo.sh" replace 1 "eat apples
|
"$HOME/bin/todo.sh" replace 1 "eat apples
|
||||||
eat oranges
|
eat oranges
|
||||||
drink milk" > $HOME/output.multi
|
drink milk" > $HOME/output.multi
|
||||||
|
|
||||||
# Test output against expected
|
# Test output against expected
|
||||||
@@ -43,7 +43,7 @@ cat /dev/null > $HOME/todo.txt
|
|||||||
|
|
||||||
# Run add
|
# Run add
|
||||||
"$HOME/bin/todo.sh" add "eat apples
|
"$HOME/bin/todo.sh" add "eat apples
|
||||||
eat oranges
|
eat oranges
|
||||||
drink milk" > $HOME/output.multi
|
drink milk" > $HOME/output.multi
|
||||||
|
|
||||||
# Test output against expected
|
# Test output against expected
|
||||||
@@ -68,7 +68,7 @@ cat /dev/null > $HOME/todo.txt
|
|||||||
|
|
||||||
# Run append
|
# Run append
|
||||||
"$HOME/bin/todo.sh" append 1 "eat apples
|
"$HOME/bin/todo.sh" append 1 "eat apples
|
||||||
eat oranges
|
eat oranges
|
||||||
drink milk" > $HOME/output.multi
|
drink milk" > $HOME/output.multi
|
||||||
|
|
||||||
# Test output against expected
|
# Test output against expected
|
||||||
@@ -93,7 +93,7 @@ cat /dev/null > $HOME/todo.txt
|
|||||||
|
|
||||||
# Run prepend
|
# Run prepend
|
||||||
"$HOME/bin/todo.sh" prepend 1 "eat apples
|
"$HOME/bin/todo.sh" prepend 1 "eat apples
|
||||||
eat oranges
|
eat oranges
|
||||||
drink milk" > $HOME/output.multi
|
drink milk" > $HOME/output.multi
|
||||||
|
|
||||||
# Test output against expected
|
# Test output against expected
|
||||||
|
|||||||
83
todo.sh
83
todo.sh
@@ -259,13 +259,10 @@ cleaninput()
|
|||||||
# Replace newlines with spaces Always
|
# Replace newlines with spaces Always
|
||||||
input=`echo $input | tr -d '\r|\n'`
|
input=`echo $input | tr -d '\r|\n'`
|
||||||
|
|
||||||
# Storing regexp in variable fixes quoting difference between
|
action_regexp="^\(append\|app\|prepend\|prep\|replace\)$"
|
||||||
# bash v3.1.x and v3.2.x see:
|
|
||||||
# http://stackoverflow.com/questions/218156/bash-regex-with-quotes
|
|
||||||
action_regexp='^(append|app|prepend|prep|replace)$'
|
|
||||||
|
|
||||||
# Check which action we are being used in as this affects what cleaning we do
|
# Check which action we are being used in as this affects what cleaning we do
|
||||||
if [[ $action =~ $action_regexp ]]; then
|
if [ `echo $action | grep -c $action_regexp` -eq 1 ]; then
|
||||||
# These actions use sed and & as the matched string so escape it
|
# These actions use sed and & as the matched string so escape it
|
||||||
input=`echo $input | sed 's/\&/\\\&/g'`
|
input=`echo $input | sed 's/\&/\\\&/g'`
|
||||||
fi
|
fi
|
||||||
@@ -503,9 +500,9 @@ _addto() {
|
|||||||
_commit() {
|
_commit() {
|
||||||
[ -z "$1" ] && die "Fatal Error: No commit message."
|
[ -z "$1" ] && die "Fatal Error: No commit message."
|
||||||
[ -z "$2" ] && die "Fatal Error: No commit files."
|
[ -z "$2" ] && die "Fatal Error: No commit files."
|
||||||
MESG="$(echo $1 | sed -e 's|\\n|\n|g')"
|
MESG="$(echo $1 | sed -e 's|\\n|\n|g')"
|
||||||
shift
|
shift
|
||||||
FILES=$*
|
FILES=$*
|
||||||
|
|
||||||
if [ $TODOTXT_GIT_VERBOSE -eq 0 ] ; then
|
if [ $TODOTXT_GIT_VERBOSE -eq 0 ] ; then
|
||||||
( cd $TODO_DIR
|
( cd $TODO_DIR
|
||||||
@@ -833,28 +830,28 @@ case $action in
|
|||||||
# Split multiple do's, if comma seperated change to whitespace sepereated
|
# Split multiple do's, if comma seperated change to whitespace sepereated
|
||||||
# Loop the 'do' function for each item
|
# Loop the 'do' function for each item
|
||||||
for item in `echo $* | tr ',' ' '`; do
|
for item in `echo $* | tr ',' ' '`; do
|
||||||
[ -z "$item" ] && die "$errmsg"
|
[ -z "$item" ] && die "$errmsg"
|
||||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
|
|
||||||
todo=$(sed "$item!d" "$TODO_FILE")
|
todo=$(sed "$item!d" "$TODO_FILE")
|
||||||
[ -z "$todo" ] && die "$item: No such todo."
|
[ -z "$todo" ] && die "$item: No such todo."
|
||||||
|
|
||||||
# Check if this item has already been done
|
# Check if this item has already been done
|
||||||
if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then
|
if [ `echo $todo | grep -c "^x "` -eq 0 ] ; then
|
||||||
now=`date '+%Y-%m-%d'`
|
now=`date '+%Y-%m-%d'`
|
||||||
# remove priority once item is done
|
# remove priority once item is done
|
||||||
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
||||||
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && {
|
[ $TODOTXT_VERBOSE -gt 0 ] && {
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
echo "$item: $newtodo"
|
echo "$item: $newtodo"
|
||||||
echo "TODO: $item marked as done."
|
echo "TODO: $item marked as done."
|
||||||
}
|
}
|
||||||
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
|
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
|
||||||
_commit "TODO: '$todo' marked as done." $TODO_FILE
|
_commit "TODO: '$todo' marked as done." $TODO_FILE
|
||||||
else
|
else
|
||||||
echo "$item is already marked done"
|
echo "$item is already marked done"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||||
@@ -862,6 +859,28 @@ case $action in
|
|||||||
fi
|
fi
|
||||||
cleanup ;;
|
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" )
|
"help" )
|
||||||
if [ -t 1 ] ; then # STDOUT is a TTY
|
if [ -t 1 ] ; then # STDOUT is a TTY
|
||||||
if (exec which ${PAGER:-less} 2>/dev/null >/dev/null); then
|
if (exec which ${PAGER:-less} 2>/dev/null >/dev/null); then
|
||||||
@@ -1008,7 +1027,7 @@ case $action in
|
|||||||
|
|
||||||
# If priority isn't set prepend
|
# If priority isn't set prepend
|
||||||
if [ -z $priority ]; then
|
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 ] && {
|
[ $TODOTXT_VERBOSE -gt 0 ] && {
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
echo "$item: $newtodo"
|
echo "$item: $newtodo"
|
||||||
@@ -1016,7 +1035,7 @@ case $action in
|
|||||||
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
|
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
|
||||||
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
|
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
|
||||||
$TODO_FILE
|
$TODO_FILE
|
||||||
else
|
else
|
||||||
echo "TODO: Error prepending task $item."
|
echo "TODO: Error prepending task $item."
|
||||||
fi
|
fi
|
||||||
# If priority is set, remove priority, prepend and add back priority
|
# If priority is set, remove priority, prepend and add back priority
|
||||||
@@ -1029,9 +1048,9 @@ case $action in
|
|||||||
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
|
[ $TODOTXT_GIT_ENABLED -eq 1 ] && \
|
||||||
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
|
_commit "TODO: Prepended '$todo' w/ '$input' on line $item." \
|
||||||
$TODO_FILE
|
$TODO_FILE
|
||||||
else
|
else
|
||||||
echo "TODO: Error prepending task $item."
|
echo "TODO: Error prepending task $item."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user