Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ginatrapani/todo.txt-cli
base: 322c6b95d6
...
head fork: ginatrapani/todo.txt-cli
compare: 137140a542
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 15 additions and 6 deletions.
  1. +8 −0 tests/t1100-replace.sh
  2. +7 −6 todo.sh
View
8 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' <<EOF
+>>> 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
View
13 todo.sh
@@ -389,21 +389,22 @@ replaceOrPrepend()
else
input=$*
fi
- cleaninput "for sed"
# Retrieve existing priority and prepended date
- 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")
+ local -r priAndDateExpr='^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}'
+ priority=$(sed -e "$item!d" -e "${item}s/${priAndDateExpr}.*/\\1/" "$TODO_FILE")
+ prepdate=$(sed -e "$item!d" -e "${item}s/${priAndDateExpr}.*/\\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/${priAndDateExpr}.*/\\1\\2/")" ]; then
+ # If the replaced text starts with a [priority +] date, it will replace
+ # the existing date, too.
prepdate=
fi
# Temporarily remove any existing priority and prepended date, perform the
# change (replace/prepend) and re-insert the existing priority and prepended
# date again.
+ cleaninput "for sed"
sed -i.bak -e "$item s/^${priority}${prepdate}//" -e "$item s|^.*|${priority}${prepdate}${input}${backref}|" "$TODO_FILE"
if [ $TODOTXT_VERBOSE -gt 0 ]; then
getNewtodo "$item"

No commit comments for this range

Something went wrong with that request. Please try again.