Merge branch 'the1ts/master'
This commit is contained in:
@@ -62,6 +62,17 @@ replaced with
|
|||||||
4: collect the eggs
|
4: collect the eggs
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'replace with priority' <<EOF
|
||||||
|
>>> todo.sh pri 4 a
|
||||||
|
4: (A) collect the eggs
|
||||||
|
TODO: 4 prioritized (A).
|
||||||
|
|
||||||
|
>>> todo.sh replace 4 "collect the bread"
|
||||||
|
4: (A) collect the eggs
|
||||||
|
replaced with
|
||||||
|
4: (A) collect the bread
|
||||||
|
EOF
|
||||||
|
|
||||||
test_todo_session 'replace error' << EOF
|
test_todo_session 'replace error' << EOF
|
||||||
>>> todo.sh replace 10 "hej!"
|
>>> todo.sh replace 10 "hej!"
|
||||||
=== 1
|
=== 1
|
||||||
|
|||||||
55
tests/t1400-prepend.sh
Executable file
55
tests/t1400-prepend.sh
Executable file
@@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='basic prepend functionality
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
test_todo_session 'prepend usage' <<EOF
|
||||||
|
>>> todo.sh prepend B B
|
||||||
|
usage: todo.sh prepend ITEM# "TEXT TO PREPEND"
|
||||||
|
=== 1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > todo.txt <<EOF
|
||||||
|
(B) smell the uppercase Roses +flowers @outside
|
||||||
|
notice the sunflowers
|
||||||
|
stop
|
||||||
|
EOF
|
||||||
|
test_todo_session 'basic prepend' <<EOF
|
||||||
|
>>> todo.sh list
|
||||||
|
[0;32m1 (B) smell the uppercase Roses +flowers @outside[0m
|
||||||
|
2 notice the sunflowers
|
||||||
|
3 stop
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown from $HOME/todo.txt
|
||||||
|
|
||||||
|
>>> todo.sh -p list
|
||||||
|
1 (B) smell the uppercase Roses +flowers @outside
|
||||||
|
2 notice the sunflowers
|
||||||
|
3 stop
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown from $HOME/todo.txt
|
||||||
|
|
||||||
|
>>> todo.sh prepend 2 test
|
||||||
|
2: test notice the sunflowers
|
||||||
|
|
||||||
|
>>> todo.sh -p list
|
||||||
|
1 (B) smell the uppercase Roses +flowers @outside
|
||||||
|
3 stop
|
||||||
|
2 test notice the sunflowers
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown from $HOME/todo.txt
|
||||||
|
|
||||||
|
>>> todo.sh prepend 1 test
|
||||||
|
1: (B) test smell the uppercase Roses +flowers @outside
|
||||||
|
|
||||||
|
>>> todo.sh -p list
|
||||||
|
1 (B) test smell the uppercase Roses +flowers @outside
|
||||||
|
3 stop
|
||||||
|
2 test notice the sunflowers
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown from $HOME/todo.txt
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
72
tests/t1500-do.sh
Executable file
72
tests/t1500-do.sh
Executable file
@@ -0,0 +1,72 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='do functionality
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
#DATE=`date '+%Y-%m-%d'`
|
||||||
|
|
||||||
|
test_todo_session 'do usage' <<EOF
|
||||||
|
>>> todo.sh do B B
|
||||||
|
usage: todo.sh do ITEM#
|
||||||
|
=== 1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > todo.txt <<EOF
|
||||||
|
smell the uppercase Roses +flowers @outside
|
||||||
|
notice the sunflowers
|
||||||
|
stop
|
||||||
|
remove1
|
||||||
|
remove2
|
||||||
|
remove3
|
||||||
|
remove4
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'basic do' <<EOF
|
||||||
|
>>> todo.sh list
|
||||||
|
2 notice the sunflowers
|
||||||
|
4 remove1
|
||||||
|
5 remove2
|
||||||
|
6 remove3
|
||||||
|
7 remove4
|
||||||
|
1 smell the uppercase Roses +flowers @outside
|
||||||
|
3 stop
|
||||||
|
--
|
||||||
|
TODO: 7 of 7 tasks shown from $HOME/todo.txt
|
||||||
|
|
||||||
|
>>> todo.sh do 7,6
|
||||||
|
7: x 2009-02-13 remove4
|
||||||
|
TODO: 7 marked as done.
|
||||||
|
6: x 2009-02-13 remove3
|
||||||
|
TODO: 6 marked as done.
|
||||||
|
x 2009-02-13 remove3
|
||||||
|
x 2009-02-13 remove4
|
||||||
|
TODO: $HOME/todo.txt archived.
|
||||||
|
|
||||||
|
>>> todo.sh -p list
|
||||||
|
2 notice the sunflowers
|
||||||
|
4 remove1
|
||||||
|
5 remove2
|
||||||
|
1 smell the uppercase Roses +flowers @outside
|
||||||
|
3 stop
|
||||||
|
--
|
||||||
|
TODO: 5 of 5 tasks shown from $HOME/todo.txt
|
||||||
|
|
||||||
|
>>> todo.sh do 5 4
|
||||||
|
5: x 2009-02-13 remove2
|
||||||
|
TODO: 5 marked as done.
|
||||||
|
4: x 2009-02-13 remove1
|
||||||
|
TODO: 4 marked as done.
|
||||||
|
x 2009-02-13 remove1
|
||||||
|
x 2009-02-13 remove2
|
||||||
|
TODO: $HOME/todo.txt archived.
|
||||||
|
|
||||||
|
>>> todo.sh -p list
|
||||||
|
2 notice the sunflowers
|
||||||
|
1 smell the uppercase Roses +flowers @outside
|
||||||
|
3 stop
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown from $HOME/todo.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
70
todo.sh
70
todo.sh
@@ -675,21 +675,27 @@ case $action in
|
|||||||
|
|
||||||
"do" )
|
"do" )
|
||||||
errmsg="usage: $TODO_SH do ITEM#"
|
errmsg="usage: $TODO_SH do ITEM#"
|
||||||
item=$2
|
# shift so we get arguments to the do request
|
||||||
[ -z "$item" ] && die "$errmsg"
|
shift;
|
||||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
|
||||||
|
|
||||||
todo=$(sed "$item!d" "$TODO_FILE")
|
# Split multiple do's, if comma seperated change to whitespace sepereated
|
||||||
[ -z "$todo" ] && die "$item: No such todo."
|
# Loop the 'do' function for each item
|
||||||
|
for item in `echo $* | tr ',' ' '`; do
|
||||||
now=`date '+%Y-%m-%d'`
|
[ -z "$item" ] && die "$errmsg"
|
||||||
# remove priority once item is done
|
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||||
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
|
||||||
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
todo=$(sed "$item!d" "$TODO_FILE")
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
[ -z "$todo" ] && die "$item: No such todo."
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done."
|
|
||||||
|
|
||||||
|
now=`date '+%Y-%m-%d'`
|
||||||
|
# remove priority once item is done
|
||||||
|
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
||||||
|
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done."
|
||||||
|
done
|
||||||
|
|
||||||
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||||
archive
|
archive
|
||||||
fi
|
fi
|
||||||
@@ -818,13 +824,29 @@ case $action in
|
|||||||
else
|
else
|
||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Test for then set priority
|
||||||
|
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
|
||||||
|
priority=$(sed "$item!d" "$TODO_FILE" | awk -F '\\(|\\)' '{print $2}')
|
||||||
|
fi
|
||||||
|
|
||||||
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
# If priority isn't set prepend
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
if [ -z $priority ]; then
|
||||||
|
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
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
|
||||||
|
else
|
||||||
|
if sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1 &|" "$TODO_FILE"; then
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
|
else
|
||||||
|
echo "TODO: Error prepending task $item."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
"pri" | "p" )
|
"pri" | "p" )
|
||||||
@@ -861,6 +883,11 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
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."
|
||||||
|
|
||||||
|
# Test for then set priority
|
||||||
|
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
|
||||||
|
priority=$(sed "$item!d" "$TODO_FILE" | awk -F '\\(|\\)' '{print $2}')
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||||
echo -n "Replacement: "
|
echo -n "Replacement: "
|
||||||
read input
|
read input
|
||||||
@@ -868,7 +895,12 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
|
# If priority isn't set replace, if it is remove priority, replace then add priority again
|
||||||
|
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"
|
||||||
|
fi
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
|
[ $TODOTXT_VERBOSE -gt 0 ] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $todo"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $todo"
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "replaced with"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "replaced with"
|
||||||
|
|||||||
Reference in New Issue
Block a user