Refactored various add functionality to one function. Added tests.
- 'add' and 'addm' now 'addto' with $TODO_FILE instead of user supplied file - 'addto' now shows the capitalized filename in place of 'TODO:'. For example, adding to garden.txt produces a output prefixed by 'GARDEN:' (Probably the most controversial part of this commit and up for discussion. If kept, the 'listfile' output should be made to match. Note that this convention would then minimize standard output by dropping the file name.) - All existing add/addm/add-date tests pass. Two new test sequences were added to test 'addto' and 'listfile' functionality. - A space/tab nuissance was cleared up in the tests/README file.
This commit is contained in:
@@ -105,7 +105,7 @@ First digit tells the family:
|
|||||||
|
|
||||||
0 - the absolute basics and global stuff
|
0 - the absolute basics and global stuff
|
||||||
1 - basic every-day usage
|
1 - basic every-day usage
|
||||||
2 - add ins
|
2 - add ins
|
||||||
|
|
||||||
Second digit tells the particular command we are testing.
|
Second digit tells the particular command we are testing.
|
||||||
|
|
||||||
|
|||||||
78
tests/t1020-addtolistfile.sh
Executable file
78
tests/t1020-addtolistfile.sh
Executable file
@@ -0,0 +1,78 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='basic addto and list functionality
|
||||||
|
|
||||||
|
This test just makes sure the basic addto and listfile
|
||||||
|
commands work, including support for filtering.
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Addto and listfile
|
||||||
|
#
|
||||||
|
test_todo_session 'nonexistant file' <<EOF
|
||||||
|
>>> todo.sh addto garden.txt notice the daisies
|
||||||
|
TODO: Destination file $HOME/garden.txt does not exist.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
touch "$HOME/garden.txt"
|
||||||
|
|
||||||
|
test_todo_session 'basic addto/listfile' <<EOF
|
||||||
|
>>> todo.sh addto garden.txt notice the daisies
|
||||||
|
GARDEN: 'notice the daisies' added on line 1.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt
|
||||||
|
1 notice the daisies
|
||||||
|
--
|
||||||
|
TODO: 1 of 1 tasks shown from garden.txt
|
||||||
|
|
||||||
|
>>> todo.sh addto garden.txt smell the roses
|
||||||
|
GARDEN: 'smell the roses' added on line 2.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt
|
||||||
|
1 notice the daisies
|
||||||
|
2 smell the roses
|
||||||
|
--
|
||||||
|
TODO: 2 of 2 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
#
|
||||||
|
# Filter
|
||||||
|
#
|
||||||
|
test_todo_session 'basic listfile filtering' <<EOF
|
||||||
|
>>> todo.sh listfile garden.txt daisies
|
||||||
|
1 notice the daisies
|
||||||
|
--
|
||||||
|
TODO: 1 of 2 tasks shown from garden.txt
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt smell
|
||||||
|
2 smell the roses
|
||||||
|
--
|
||||||
|
TODO: 1 of 2 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'case-insensitive filtering' <<EOF
|
||||||
|
>>> todo.sh addto garden.txt smell the uppercase Roses
|
||||||
|
GARDEN: 'smell the uppercase Roses' added on line 3.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt roses
|
||||||
|
2 smell the roses
|
||||||
|
3 smell the uppercase Roses
|
||||||
|
--
|
||||||
|
TODO: 2 of 3 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'addto with &' <<EOF
|
||||||
|
>>> todo.sh addto garden.txt "dig the garden & water the flowers"
|
||||||
|
GARDEN: 'dig the garden & water the flowers' added on line 4.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt
|
||||||
|
4 dig the garden & water the flowers
|
||||||
|
1 notice the daisies
|
||||||
|
2 smell the roses
|
||||||
|
3 smell the uppercase Roses
|
||||||
|
--
|
||||||
|
TODO: 4 of 4 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
71
tests/t1030-addto-date.sh
Executable file
71
tests/t1030-addto-date.sh
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='test the date on addto feature
|
||||||
|
|
||||||
|
Tests paths by which we might automatically add
|
||||||
|
a date to each item.
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
touch "$HOME/garden.txt"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Add and list
|
||||||
|
#
|
||||||
|
test_todo_session 'cmd line first day' <<EOF
|
||||||
|
>>> todo.sh -t addto garden.txt notice the daisies
|
||||||
|
GARDEN: '2009-02-13 notice the daisies' added on line 1.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt
|
||||||
|
1 2009-02-13 notice the daisies
|
||||||
|
--
|
||||||
|
TODO: 1 of 1 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_tick
|
||||||
|
|
||||||
|
test_todo_session 'cmd line second day' <<EOF
|
||||||
|
>>> todo.sh -t addto garden.txt smell the roses
|
||||||
|
GARDEN: '2009-02-14 smell the roses' added on line 2.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt
|
||||||
|
1 2009-02-13 notice the daisies
|
||||||
|
2 2009-02-14 smell the roses
|
||||||
|
--
|
||||||
|
TODO: 2 of 2 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_tick
|
||||||
|
|
||||||
|
test_todo_session 'cmd line third day' <<EOF
|
||||||
|
>>> todo.sh -t addto garden.txt mow the lawn
|
||||||
|
GARDEN: '2009-02-15 mow the lawn' added on line 3.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt
|
||||||
|
1 2009-02-13 notice the daisies
|
||||||
|
2 2009-02-14 smell the roses
|
||||||
|
3 2009-02-15 mow the lawn
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Switch to config file
|
||||||
|
echo "export TODOTXT_DATE_ON_ADD=1" >> todo.cfg
|
||||||
|
|
||||||
|
# Bump the clock, for good measure.
|
||||||
|
test_tick 3600
|
||||||
|
|
||||||
|
test_todo_session 'config file third day' <<EOF
|
||||||
|
>>> todo.sh addto garden.txt take out the trash
|
||||||
|
GARDEN: '2009-02-15 take out the trash' added on line 4.
|
||||||
|
|
||||||
|
>>> todo.sh listfile garden.txt
|
||||||
|
1 2009-02-13 notice the daisies
|
||||||
|
2 2009-02-14 smell the roses
|
||||||
|
3 2009-02-15 mow the lawn
|
||||||
|
4 2009-02-15 take out the trash
|
||||||
|
--
|
||||||
|
TODO: 4 of 4 tasks shown from garden.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
46
todo.sh
46
todo.sh
@@ -473,6 +473,24 @@ fi
|
|||||||
# === HEAVY LIFTING ===
|
# === HEAVY LIFTING ===
|
||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
|
|
||||||
|
_addto() {
|
||||||
|
file="$1"
|
||||||
|
input="$2"
|
||||||
|
cleaninput $input
|
||||||
|
|
||||||
|
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
||||||
|
now=`date '+%Y-%m-%d'`
|
||||||
|
input="$now $input"
|
||||||
|
fi
|
||||||
|
echo "$input" >> "$file"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && {
|
||||||
|
TASKNUM=$(sed -n '$ =' "$file")
|
||||||
|
BASE=$(basename "$file")
|
||||||
|
PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z])
|
||||||
|
echo "${PREFIX}: '$input' added on line $TASKNUM."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_list() {
|
_list() {
|
||||||
local FILE="$1"
|
local FILE="$1"
|
||||||
## If the file starts with a "/" use absolute path. Otherwise,
|
## If the file starts with a "/" use absolute path. Otherwise,
|
||||||
@@ -616,17 +634,7 @@ case $action in
|
|||||||
shift
|
shift
|
||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
cleaninput $input
|
_addto "$TODO_FILE" "$input"
|
||||||
|
|
||||||
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
|
||||||
now=`date '+%Y-%m-%d'`
|
|
||||||
input="$now $input"
|
|
||||||
fi
|
|
||||||
echo "$input" >> "$TODO_FILE"
|
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && {
|
|
||||||
TASKNUM=$(sed -n '$ =' "$TODO_FILE")
|
|
||||||
echo "TODO: '$input' added on line $TASKNUM."
|
|
||||||
}
|
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
"addm")
|
"addm")
|
||||||
@@ -646,15 +654,7 @@ case $action in
|
|||||||
|
|
||||||
# Treat each line seperately
|
# Treat each line seperately
|
||||||
for line in $input ; do
|
for line in $input ; do
|
||||||
if [[ $TODOTXT_DATE_ON_ADD = 1 ]]; then
|
_addto "$TODO_FILE" "$line"
|
||||||
now=`date '+%Y-%m-%d'`
|
|
||||||
line="$now $line"
|
|
||||||
fi
|
|
||||||
echo "$line" >> "$TODO_FILE"
|
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && {
|
|
||||||
TASKNUM=$(sed -n '$ =' "$TODO_FILE")
|
|
||||||
echo "TODO: '$line' added on line $TASKNUM."
|
|
||||||
}
|
|
||||||
done
|
done
|
||||||
IFS=$SAVEIFS
|
IFS=$SAVEIFS
|
||||||
cleanup;;
|
cleanup;;
|
||||||
@@ -668,11 +668,7 @@ case $action in
|
|||||||
input=$*
|
input=$*
|
||||||
|
|
||||||
if [ -f "$dest" ]; then
|
if [ -f "$dest" ]; then
|
||||||
echo "$input" >> "$dest"
|
_addto "$dest" "$input"
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && {
|
|
||||||
TASKNUM=$(sed -n '$ =' "$dest")
|
|
||||||
echo "TODO: '$input' added to $dest on line $TASKNUM."
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
echo "TODO: Destination file $dest does not exist."
|
echo "TODO: Destination file $dest does not exist."
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user