diff --git a/tests/t1100-replace.sh b/tests/t1100-replace.sh index 9336304..77ca9e1 100755 --- a/tests/t1100-replace.sh +++ b/tests/t1100-replace.sh @@ -164,4 +164,12 @@ TODO: Replaced task with: 1 (A) 2010-07-04 this also has a new date EOF +echo '2009-02-13 this is just a new one' > todo.txt +test_todo_session 'replace with prepended priority and date replaces existing date' <>> todo.sh replace 1 '(B) 2010-07-04 this also has a new date' +1 2009-02-13 this is just a new one +TODO: Replaced task with: +1 (B) 2010-07-04 this also has a new date +EOF + test_done diff --git a/todo.sh b/todo.sh index 4837120..082c495 100755 --- a/todo.sh +++ b/todo.sh @@ -395,9 +395,9 @@ replaceOrPrepend() priority=$(sed -e "$item!d" -e $item's/^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1/' "$TODO_FILE") prepdate=$(sed -e "$item!d" -e $item's/^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\2/' "$TODO_FILE") - if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e 's/^\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\}\)\{0,1\}.*/\1/')" ]; then - # If the replaced text starts with a date, it will replace the existing - # date, too. + if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e 's/^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1\2/')" ]; then + # If the replaced text starts with a [priority +] date, it will replace + # the existing date, too. prepdate= fi