Merge branch 'the1ts/addm'

This commit is contained in:
Gina Trapani
2009-09-08 11:58:04 -07:00
2 changed files with 62 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ echo "1: smell the cheese
replaced with
1: eat apples eat oranges drink milk">$HOME/expect.multi
test_expect_success 'multiline item replace' '
test_expect_success 'multiline squash item replace' '
(
# Prepare single line todo file
cat /dev/null > $HOME/todo.txt
@@ -35,7 +35,7 @@ fi
# Create the expected file
echo "TODO: 'eat apples eat oranges drink milk' added on line 2.">$HOME/expect.multi
test_expect_success 'multiline item add' '
test_expect_success 'multiline squash item add' '
(
# Prepare single line todo file
cat /dev/null > $HOME/todo.txt
@@ -60,7 +60,7 @@ fi
# Create the expected file
echo "1: smell the cheese eat apples eat oranges drink milk">$HOME/expect.multi
test_expect_success 'multiline item append' '
test_expect_success 'multiline squash item append' '
(
# Prepare single line todo file
cat /dev/null > $HOME/todo.txt
@@ -85,7 +85,7 @@ fi
# Create the expected file
echo "1: eat apples eat oranges drink milk smell the cheese">$HOME/expect.multi
test_expect_success 'multiline item prepend' '
test_expect_success 'multiline squash item prepend' '
(
# Prepare single line todo file
cat /dev/null > $HOME/todo.txt
@@ -106,4 +106,25 @@ fi
)
'
## Multiple line addition
# Create the expected file
echo -e "TODO: 'eat apples' added on line 2.\nTODO: 'eat oranges' added on line 3.\nTODO: 'drink milk' added on line 4.">$HOME/expect.multi
test_expect_success 'actual multiline add' '
(
# Run addm
"$HOME/bin/todo.sh" addm "eat apples
eat oranges
drink milk" > $HOME/output.multi
# Test output against expected
diff "$HOME/output.multi" "$HOME/expect.multi"
if [ $? -ne 0 ]; then
exit 1
else
exit 0
fi
)
'
test_done

37
todo.sh
View File

@@ -41,6 +41,8 @@ shorthelp()
Actions:
add|a "THING I NEED TO DO +project @context"
addto DEST "TEXT TO ADD"
addm "THINGS I NEED TO DO
MORE THINGS I NEED TO DO"
append|app NUMBER "TEXT TO APPEND"
archive
command [ACTIONS]
@@ -77,6 +79,13 @@ help()
Project and context notation optional.
Quotes optional.
addm "FIRST THING I NEED TO DO +project1 @context
SECOND THING I NEED TO DO +project2 @context"
Adds FIRST THING I NEED TO DO to your todo.txt on its own line and
Adds SECOND THING I NEED TO DO to you todo.txt on its own line.
Project and context notation optional.
Quotes optional.
addto DEST "TEXT TO ADD"
Adds a line of text to any file located in the todo.txt directory.
For example, addto inbox.txt "decide about vacation"
@@ -612,6 +621,34 @@ case $action in
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;;
"addm")
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Add: "
read input
else
[ -z "$2" ] && die "usage: $TODO_SH addm \"TODO ITEM\""
shift
input=$*
fi
# Set Internal Field Seperator as newline so we can
# loop across multiple lines
SAVEIFS=$IFS
IFS=$'\n'
# Treat each line seperately
for line in $input ; do
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
now=`date '+%Y-%m-%d'`
line="$now $line"
fi
echo "$line" >> "$TODO_FILE"
TASKNUM=$(sed -n '$ =' "$TODO_FILE")
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$line' added on line $TASKNUM."
done
IFS=$SAVEIFS
cleanup;;
"addto" )
[ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\""
dest="$TODO_DIR/$2"