Configure cleaninput() sed-escaping via argument instead of magic words.

Encoding the actions that require the additional sed-escaping inside cleaninput() is cumbersome and error-prone. Instead, let the calling action tell cleaninput() that it wants this.
This commit is contained in:
Ingo Karkat
2011-05-11 15:48:22 +02:00
parent 4643dce698
commit 41dba2d636

11
todo.sh
View File

@@ -271,11 +271,8 @@ cleaninput()
# Replace newlines with spaces Always # Replace newlines with spaces Always
input=`echo $input | tr -d '\r\n'` input=`echo $input | tr -d '\r\n'`
action_regexp="^\(append\|app\|prepend\|prep\|replace\)$" if [ "$1" = "for sed" ]; then
# This action uses sed and & as the matched string so escape it
# Check which action we are being used in as this affects what cleaning we do
if [ `echo $action | grep -c $action_regexp` -eq 1 ]; then
# These actions use sed and & as the matched string so escape it
input=`echo $input | sed 's/\&/\\\&/g'` input=`echo $input | sed 's/\&/\\\&/g'`
fi fi
} }
@@ -321,7 +318,7 @@ replaceOrPrepend()
else else
input=$* input=$*
fi fi
cleaninput cleaninput "for sed"
# Retrieve existing priority and prepended date # Retrieve existing priority and prepended date
priority=$(sed -e "$item!d" -e $item's/^\(([A-Z]) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1/' "$TODO_FILE") priority=$(sed -e "$item!d" -e $item's/^\(([A-Z]) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1/' "$TODO_FILE")
@@ -842,7 +839,7 @@ case $action in
[$SENTENCE_DELIMITERS]*) appendspace=;; [$SENTENCE_DELIMITERS]*) appendspace=;;
*) appendspace=" ";; *) appendspace=" ";;
esac esac
cleaninput cleaninput "for sed"
if sed -i.bak $item" s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then if sed -i.bak $item" s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then
if [ $TODOTXT_VERBOSE -gt 0 ]; then if [ $TODOTXT_VERBOSE -gt 0 ]; then