From 2f4ba269947ef983bb0e9e2d7c10c8b2a008ebda Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Mon, 5 Jul 2010 13:49:58 +0200 Subject: [PATCH] ENH: Sentence delimiters for append action. This fixes a personal annoyance. If the text to be appended to the task begins with one of the delimiter characters, no whitespace is inserted in between. This makes appending to an enumeration (todo.sh add 42 ", foo") syntactically correct. The list of delimiters is configurable (for personal preferences / non-English languages) via SENTENCE_DELIMITERS in the config file. --- tests/t1600-append.sh | 29 +++++++++++++++++++++++++++++ todo.sh | 12 +++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/t1600-append.sh b/tests/t1600-append.sh index 885074e..57ee99e 100755 --- a/tests/t1600-append.sh +++ b/tests/t1600-append.sh @@ -44,4 +44,33 @@ test_todo_session 'append error' << EOF 10: No such task. EOF +cat > todo.txt <>> todo.sh append 1 ", lilies and roses" +1: notice the daisies, lilies and roses + +>>> todo.sh append 1 "; see the wasps" +1: notice the daisies, lilies and roses; see the wasps + +>>> todo.sh append 1 "& bees" +1: notice the daisies, lilies and roses; see the wasps & bees +EOF + +cp todo.cfg special-delimiters.cfg +cat >> special-delimiters.cfg <>> todo.sh -d special-delimiters.cfg append 1 "&beans" +1: notice the daisies, lilies and roses; see the wasps & bees&beans + +>>> todo.sh -d special-delimiters.cfg append 1 "%foo" +1: notice the daisies, lilies and roses; see the wasps & bees&beans %foo + +>>> todo.sh -d special-delimiters.cfg append 1 "*2" +1: notice the daisies, lilies and roses; see the wasps & bees&beans %foo*2 +EOF + test_done diff --git a/todo.sh b/todo.sh index 8b30d10..20dc20e 100755 --- a/todo.sh +++ b/todo.sh @@ -469,6 +469,12 @@ export PRI_B=$GREEN # color for B priority export PRI_C=$LIGHT_BLUE # color for C priority export PRI_X=$WHITE # color for rest of them +# Default sentence delimiters for todo.sh append. +# If the text to be appended to the task begins with one of these characters, no +# whitespace is inserted in between. This makes appending to an enumeration +# (todo.sh add 42 ", foo") syntactically correct. +export SENTENCE_DELIMITERS=',.:;' + [ -e "$TODOTXT_CFG_FILE" ] || { CFG_FILE_ALT="$HOME/todo.cfg" @@ -746,9 +752,13 @@ case $action in else input=$* fi + case "$input" in + [$SENTENCE_DELIMITERS]*) appendspace=;; + *) appendspace=" ";; + esac cleaninput $input - if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then + if sed -i.bak $item" s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then [ $TODOTXT_VERBOSE -gt 0 ] && { newtodo=$(sed "$item!d" "$TODO_FILE") echo "$item: $newtodo"