Bug Fix: prepend not correct on prioritized tasks
Check for priority, if one exists, remove, prepend and add back. If priority doesn't exist just runs the normal prepend functionality.
This commit is contained in:
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
|
||||
26
todo.sh
26
todo.sh
@@ -819,12 +819,28 @@ case $action in
|
||||
input=$*
|
||||
fi
|
||||
|
||||
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
# 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 priority isn't set prepend
|
||||
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"
|
||||
else
|
||||
echo "TODO: Error prepending task $item."
|
||||
fi
|
||||
else
|
||||
echo "TODO: Error prepending task $item."
|
||||
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;;
|
||||
|
||||
"pri" | "p" )
|
||||
|
||||
Reference in New Issue
Block a user