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
This commit is contained in:
66
todo.sh
66
todo.sh
@@ -158,6 +158,7 @@ help()
|
|||||||
TODOTXT_PLAIN=1 is same as option -p
|
TODOTXT_PLAIN=1 is same as option -p
|
||||||
TODOTXT_DATE_ON_ADD=1 is same as option -t
|
TODOTXT_DATE_ON_ADD=1 is same as option -t
|
||||||
TODOTXT_VERBOSE=1 is same as option -v
|
TODOTXT_VERBOSE=1 is same as option -v
|
||||||
|
TODOTXT_UNDEF_CUSTOM_ACTIONS=1 disables .todo.actions.d
|
||||||
EndHelp
|
EndHelp
|
||||||
|
|
||||||
if [ -d "$HOME/.todo.actions.d" ]
|
if [ -d "$HOME/.todo.actions.d" ]
|
||||||
@@ -209,37 +210,37 @@ while getopts ":fhpnatvV+@Pd:" Option
|
|||||||
do
|
do
|
||||||
case $Option in
|
case $Option in
|
||||||
'@' )
|
'@' )
|
||||||
## HIDE_CONTEXT_NAMES starts at zero (false); increment it to one
|
## HIDE_CONTEXT_NAMES starts at zero (false); increment it to one
|
||||||
## (true) the first time this flag is seen. Each time the flag
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
## is seen after that, increment it again so that an even
|
## is seen after that, increment it again so that an even
|
||||||
## number hides project names and an odd number shows project
|
## number hides project names and an odd number shows project
|
||||||
## names.
|
## names.
|
||||||
: $(( HIDE_CONTEXT_NAMES++ ))
|
: $(( HIDE_CONTEXT_NAMES++ ))
|
||||||
if [ $(( $HIDE_CONTEXT_NAMES % 2 )) -eq 0 ]
|
if [ $(( $HIDE_CONTEXT_NAMES % 2 )) -eq 0 ]
|
||||||
then
|
then
|
||||||
## Zero or even value -- show context names
|
## Zero or even value -- show context names
|
||||||
unset HIDE_CONTEXTS_SUBSTITUTION
|
unset HIDE_CONTEXTS_SUBSTITUTION
|
||||||
else
|
else
|
||||||
## One or odd value -- hide context names
|
## One or odd value -- hide context names
|
||||||
HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}'
|
HIDE_CONTEXTS_SUBSTITUTION='[[:space:]]@[^[:space:]]\{1,\}'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
'+' )
|
'+' )
|
||||||
## HIDE_PROJECT_NAMES starts at zero (false); increment it to one
|
## HIDE_PROJECT_NAMES starts at zero (false); increment it to one
|
||||||
## (true) the first time this flag is seen. Each time the flag
|
## (true) the first time this flag is seen. Each time the flag
|
||||||
## is seen after that, increment it again so that an even
|
## is seen after that, increment it again so that an even
|
||||||
## number hides project names and an odd number shows project
|
## number hides project names and an odd number shows project
|
||||||
## names.
|
## names.
|
||||||
: $(( HIDE_PROJECT_NAMES++ ))
|
: $(( HIDE_PROJECT_NAMES++ ))
|
||||||
if [ $(( $HIDE_PROJECT_NAMES % 2 )) -eq 0 ]
|
if [ $(( $HIDE_PROJECT_NAMES % 2 )) -eq 0 ]
|
||||||
then
|
then
|
||||||
## Zero or even value -- show project names
|
## Zero or even value -- show project names
|
||||||
unset HIDE_PROJECTS_SUBSTITUTION
|
unset HIDE_PROJECTS_SUBSTITUTION
|
||||||
else
|
else
|
||||||
## One or odd value -- hide project names
|
## One or odd value -- hide project names
|
||||||
HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}'
|
HIDE_PROJECTS_SUBSTITUTION='[[:space:]][+][^[:space:]]\{1,\}'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
a )
|
a )
|
||||||
TODOTXT_AUTO_ARCHIVE=0
|
TODOTXT_AUTO_ARCHIVE=0
|
||||||
;;
|
;;
|
||||||
@@ -295,6 +296,7 @@ TODOTXT_FORCE=${TODOTXT_FORCE:-0}
|
|||||||
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
|
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
|
||||||
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1}
|
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1}
|
||||||
TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
|
TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
|
||||||
|
TODOTXT_UNDEF_CUSTOM_ACTIONS=${TODOTXT_UNDEF_CUSTOM_ACTIONS:-0}
|
||||||
|
|
||||||
[ -e "$TODOTXT_CFG_FILE" ] || {
|
[ -e "$TODOTXT_CFG_FILE" ] || {
|
||||||
CFG_FILE_ALT="$HOME/.todo.cfg"
|
CFG_FILE_ALT="$HOME/.todo.cfg"
|
||||||
@@ -305,7 +307,7 @@ TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
|
|||||||
fi
|
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"
|
TODO_SH="$0"
|
||||||
export TODO_SH
|
export TODO_SH
|
||||||
@@ -339,7 +341,7 @@ shopt -s extglob
|
|||||||
action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' )
|
action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' )
|
||||||
|
|
||||||
## Run and quit if there's a actions script
|
## 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
|
then
|
||||||
"$HOME/.todo.actions.d/$action" "$@"
|
"$HOME/.todo.actions.d/$action" "$@"
|
||||||
cleanup
|
cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user