From e0b93e48fb6af56c171b6b684681728ab552d45c Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 19 Apr 2012 14:12:35 +0200 Subject: [PATCH] Refactoring: Extract duplicated regexp for priority and date. --- todo.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/todo.sh b/todo.sh index 082c495..372024b 100755 --- a/todo.sh +++ b/todo.sh @@ -392,10 +392,11 @@ replaceOrPrepend() 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,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1\2/')" ]; then + 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=