From db6676717079be729233724bbdb70b6e069585fb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Mar 2009 10:09:32 +0100 Subject: [PATCH] Add TODOTXT_UNDEF_CUSTOM_ACTIONS for recursive call of todo.sh from actions And replace tabs by spaces. To illustrate the interest of this new variable, here is an action to replace the original add to allow a priority to be set when adding. The action itself relies on the original add, therefore the need for this new envvar. action=$1 shift [ "$action" = "usage" ] && { echo " add pri PRIORITY \"THING I NEED TO DO +project @context\"" echo " add an item and prioritize it in one step" echo "" exit } . $TODOTXT_CFG_FILE TODOTXT_UNDEF_CUSTOM_ACTIONS=1 PRIORITY=false if [ x"$1" = x"pri" -o x"$1" = x"p" ] && [[ x"$2" =~ x[a-zA-Z] ]]; then PRIORITY=$2 shift shift fi if $TODO_SH add "$@" && [ $PRIORITY != false ]; then # figure out the line of what we just added, and "do" it line=`wc -l "$TODO_FILE" | cut -d' ' -f1` $TODO_SH pri "$line" $PRIORITY fi --- todo.sh | 66 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/todo.sh b/todo.sh index f9997d8..85bf518 100755 --- a/todo.sh +++ b/todo.sh @@ -158,6 +158,7 @@ help() TODOTXT_PLAIN=1 is same as option -p TODOTXT_DATE_ON_ADD=1 is same as option -t TODOTXT_VERBOSE=1 is same as option -v + TODOTXT_UNDEF_CUSTOM_ACTIONS=1 disables .todo.actions.d EndHelp if [ -d "$HOME/.todo.actions.d" ] @@ -209,37 +210,37 @@ while getopts ":fhpnatvV+@Pd:" Option do case $Option in '@' ) - ## HIDE_CONTEXT_NAMES starts at zero (false); increment it to one - ## (true) the first time this flag is seen. Each time the flag - ## is seen after that, increment it again so that an even - ## number hides project names and an odd number shows project - ## names. - : $(( HIDE_CONTEXT_NAMES++ )) - if [ $(( $HIDE_CONTEXT_NAMES % 2 )) -eq 0 ] - then - ## Zero or even value -- show context names - unset HIDE_CONTEXTS_SUBSTITUTION - else - ## One or odd value -- hide context names - HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}' - fi - ;; + ## HIDE_CONTEXT_NAMES starts at zero (false); increment it to one + ## (true) the first time this flag is seen. Each time the flag + ## is seen after that, increment it again so that an even + ## number hides project names and an odd number shows project + ## names. + : $(( HIDE_CONTEXT_NAMES++ )) + if [ $(( $HIDE_CONTEXT_NAMES % 2 )) -eq 0 ] + then + ## Zero or even value -- show context names + unset HIDE_CONTEXTS_SUBSTITUTION + else + ## One or odd value -- hide context names + HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}' + fi + ;; '+' ) - ## HIDE_PROJECT_NAMES starts at zero (false); increment it to one - ## (true) the first time this flag is seen. Each time the flag - ## is seen after that, increment it again so that an even - ## number hides project names and an odd number shows project - ## names. - : $(( HIDE_PROJECT_NAMES++ )) - if [ $(( $HIDE_PROJECT_NAMES % 2 )) -eq 0 ] - then - ## Zero or even value -- show project names - unset HIDE_PROJECTS_SUBSTITUTION - else - ## One or odd value -- hide project names - HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}' - fi - ;; + ## HIDE_PROJECT_NAMES starts at zero (false); increment it to one + ## (true) the first time this flag is seen. Each time the flag + ## is seen after that, increment it again so that an even + ## number hides project names and an odd number shows project + ## names. + : $(( HIDE_PROJECT_NAMES++ )) + if [ $(( $HIDE_PROJECT_NAMES % 2 )) -eq 0 ] + then + ## Zero or even value -- show project names + unset HIDE_PROJECTS_SUBSTITUTION + else + ## One or odd value -- hide project names + HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}' + fi + ;; a ) TODOTXT_AUTO_ARCHIVE=0 ;; @@ -295,6 +296,7 @@ TODOTXT_FORCE=${TODOTXT_FORCE:-0} TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1} TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1} TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0} +TODOTXT_UNDEF_CUSTOM_ACTIONS=${TODOTXT_UNDEF_CUSTOM_ACTIONS:-0} [ -e "$TODOTXT_CFG_FILE" ] || { CFG_FILE_ALT="$HOME/.todo.cfg" @@ -305,7 +307,7 @@ TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0} fi } -export TODOTXT_VERBOSE TODOTXT_PLAIN TODOTXT_CFG_FILE TODOTXT_FORCE TODOTXT_PRESERVE_LINE_NUMBERS TODOTXT_AUTO_ARCHIVE TODOTXT_DATE_ON_ADD +export TODOTXT_VERBOSE TODOTXT_PLAIN TODOTXT_CFG_FILE TODOTXT_FORCE TODOTXT_PRESERVE_LINE_NUMBERS TODOTXT_AUTO_ARCHIVE TODOTXT_DATE_ON_ADD TODOTXT_UNDEF_CUSTOM_ACTIONS TODO_SH="$0" export TODO_SH @@ -339,7 +341,7 @@ shopt -s extglob action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' ) ## Run and quit if there's a actions script -if [ -d "$HOME/.todo.actions.d" -a -x "$HOME/.todo.actions.d/$action" ] +if [ $TODOTXT_UNDEF_CUSTOM_ACTIONS = 0 -a -d "$HOME/.todo.actions.d" -a -x "$HOME/.todo.actions.d/$action" ] then "$HOME/.todo.actions.d/$action" "$@" cleanup