Added new action addm

This allows addition of multiple todo items by sending multiple lines.
This commit is contained in:
Paul Mansfield
2009-09-06 18:53:31 +01:00
parent 51dd50b41d
commit 7a87077dfc
2 changed files with 62 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ echo "1: smell the cheese
replaced with replaced with
1: eat apples eat oranges drink milk">$HOME/expect.multi 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 # Prepare single line todo file
cat /dev/null > $HOME/todo.txt cat /dev/null > $HOME/todo.txt
@@ -35,7 +35,7 @@ fi
# Create the expected file # Create the expected file
echo "TODO: 'eat apples eat oranges drink milk' added on line 2.">$HOME/expect.multi 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 # Prepare single line todo file
cat /dev/null > $HOME/todo.txt cat /dev/null > $HOME/todo.txt
@@ -60,7 +60,7 @@ fi
# Create the expected file # Create the expected file
echo "1: smell the cheese eat apples eat oranges drink milk">$HOME/expect.multi 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 # Prepare single line todo file
cat /dev/null > $HOME/todo.txt cat /dev/null > $HOME/todo.txt
@@ -85,7 +85,7 @@ fi
# Create the expected file # Create the expected file
echo "1: eat apples eat oranges drink milk smell the cheese">$HOME/expect.multi 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 # Prepare single line todo file
cat /dev/null > $HOME/todo.txt 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 test_done

37
todo.sh
View File

@@ -41,6 +41,8 @@ shorthelp()
Actions: Actions:
add|a "THING I NEED TO DO +project @context" add|a "THING I NEED TO DO +project @context"
addto DEST "TEXT TO ADD" addto DEST "TEXT TO ADD"
addm "THINGS I NEED TO DO
MORE THINGS I NEED TO DO"
append|app NUMBER "TEXT TO APPEND" append|app NUMBER "TEXT TO APPEND"
archive archive
command [ACTIONS] command [ACTIONS]
@@ -77,6 +79,13 @@ help()
Project and context notation optional. Project and context notation optional.
Quotes 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" addto DEST "TEXT TO ADD"
Adds a line of text to any file located in the todo.txt directory. Adds a line of text to any file located in the todo.txt directory.
For example, addto inbox.txt "decide about vacation" For example, addto inbox.txt "decide about vacation"
@@ -604,6 +613,34 @@ case $action in
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added on line $TASKNUM." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;; 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 InternalField 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" ) "addto" )
[ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\"" [ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\""
dest="$TODO_DIR/$2" dest="$TODO_DIR/$2"