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:
11
todo.sh
11
todo.sh
@@ -271,11 +271,8 @@ cleaninput()
|
||||
# Replace newlines with spaces Always
|
||||
input=`echo $input | tr -d '\r\n'`
|
||||
|
||||
action_regexp="^\(append\|app\|prepend\|prep\|replace\)$"
|
||||
|
||||
# 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
|
||||
if [ "$1" = "for sed" ]; then
|
||||
# This action uses sed and & as the matched string so escape it
|
||||
input=`echo $input | sed 's/\&/\\\&/g'`
|
||||
fi
|
||||
}
|
||||
@@ -321,7 +318,7 @@ replaceOrPrepend()
|
||||
else
|
||||
input=$*
|
||||
fi
|
||||
cleaninput
|
||||
cleaninput "for sed"
|
||||
|
||||
# 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")
|
||||
@@ -842,7 +839,7 @@ case $action in
|
||||
[$SENTENCE_DELIMITERS]*) appendspace=;;
|
||||
*) appendspace=" ";;
|
||||
esac
|
||||
cleaninput
|
||||
cleaninput "for sed"
|
||||
|
||||
if sed -i.bak $item" s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
|
||||
Reference in New Issue
Block a user