new: Add default priority variable TODOTXT_PRIORITY_ON_ADD. (#246)
Adds the config / env variable `TODOTXT_PRIORITY_ON_ADD`, which when set to one of the capital letters `A` to `Z` is given as a priority to a new task, if a priority is not given on command line.
This commit is contained in:
33
tests/t1040-add-priority.sh
Executable file
33
tests/t1040-add-priority.sh
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
test_description='test the priority on add feature'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
## Normal use case
|
||||||
|
echo "export TODOTXT_PRIORITY_ON_ADD=A" >> todo.cfg
|
||||||
|
|
||||||
|
test_todo_session 'config file priority' <<EOF
|
||||||
|
>>> todo.sh add take out the trash
|
||||||
|
1 (A) take out the trash
|
||||||
|
TODO: 1 added.
|
||||||
|
|
||||||
|
>>> todo.sh -p list
|
||||||
|
1 (A) take out the trash
|
||||||
|
--
|
||||||
|
TODO: 1 of 1 tasks shown
|
||||||
|
EOF
|
||||||
|
|
||||||
|
## Wrong value in config var
|
||||||
|
echo "export TODOTXT_PRIORITY_ON_ADD=1" >> todo.cfg
|
||||||
|
|
||||||
|
test_todo_session 'config file wrong priority' <<EOF
|
||||||
|
>>> todo.sh add fail to take out the trash
|
||||||
|
=== 1
|
||||||
|
TODOTXT_PRIORITY_ON_ADD should be a capital letter from A to Z (it is now "1").
|
||||||
|
|
||||||
|
>>> todo.sh -p list
|
||||||
|
=== 1
|
||||||
|
TODOTXT_PRIORITY_ON_ADD should be a capital letter from A to Z (it is now "1").
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
14
todo.sh
14
todo.sh
@@ -142,6 +142,7 @@ help()
|
|||||||
TODOTXT_PRESERVE_LINE_NUMBERS is same as option -n (0)/-N (1)
|
TODOTXT_PRESERVE_LINE_NUMBERS is same as option -n (0)/-N (1)
|
||||||
TODOTXT_PLAIN is same as option -p (1)/-c (0)
|
TODOTXT_PLAIN is same as option -p (1)/-c (0)
|
||||||
TODOTXT_DATE_ON_ADD is same as option -t (1)/-T (0)
|
TODOTXT_DATE_ON_ADD is same as option -t (1)/-T (0)
|
||||||
|
TODOTXT_PRIORITY_ON_ADD=pri default priority A-Z
|
||||||
TODOTXT_VERBOSE=1 is same as option -v
|
TODOTXT_VERBOSE=1 is same as option -v
|
||||||
TODOTXT_DISABLE_FILTER=1 is same as option -x
|
TODOTXT_DISABLE_FILTER=1 is same as option -x
|
||||||
TODOTXT_DEFAULT_ACTION="" run this when called with no arguments
|
TODOTXT_DEFAULT_ACTION="" run this when called with no arguments
|
||||||
@@ -482,6 +483,7 @@ OVR_TODOTXT_FORCE="$TODOTXT_FORCE"
|
|||||||
OVR_TODOTXT_PRESERVE_LINE_NUMBERS="$TODOTXT_PRESERVE_LINE_NUMBERS"
|
OVR_TODOTXT_PRESERVE_LINE_NUMBERS="$TODOTXT_PRESERVE_LINE_NUMBERS"
|
||||||
OVR_TODOTXT_PLAIN="$TODOTXT_PLAIN"
|
OVR_TODOTXT_PLAIN="$TODOTXT_PLAIN"
|
||||||
OVR_TODOTXT_DATE_ON_ADD="$TODOTXT_DATE_ON_ADD"
|
OVR_TODOTXT_DATE_ON_ADD="$TODOTXT_DATE_ON_ADD"
|
||||||
|
OVR_TODOTXT_PRIORITY_ON_ADD="$TODOTXT_PRIORITY_ON_ADD"
|
||||||
OVR_TODOTXT_DISABLE_FILTER="$TODOTXT_DISABLE_FILTER"
|
OVR_TODOTXT_DISABLE_FILTER="$TODOTXT_DISABLE_FILTER"
|
||||||
OVR_TODOTXT_VERBOSE="$TODOTXT_VERBOSE"
|
OVR_TODOTXT_VERBOSE="$TODOTXT_VERBOSE"
|
||||||
OVR_TODOTXT_DEFAULT_ACTION="$TODOTXT_DEFAULT_ACTION"
|
OVR_TODOTXT_DEFAULT_ACTION="$TODOTXT_DEFAULT_ACTION"
|
||||||
@@ -601,6 +603,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_PRIORITY_ON_ADD=${TODOTXT_PRIORITY_ON_ADD:-}
|
||||||
TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
|
TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
|
||||||
TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2}
|
TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2}
|
||||||
TODOTXT_DISABLE_FILTER=${TODOTXT_DISABLE_FILTER:-}
|
TODOTXT_DISABLE_FILTER=${TODOTXT_DISABLE_FILTER:-}
|
||||||
@@ -740,6 +743,9 @@ fi
|
|||||||
if [ -n "$OVR_TODOTXT_DATE_ON_ADD" ] ; then
|
if [ -n "$OVR_TODOTXT_DATE_ON_ADD" ] ; then
|
||||||
TODOTXT_DATE_ON_ADD="$OVR_TODOTXT_DATE_ON_ADD"
|
TODOTXT_DATE_ON_ADD="$OVR_TODOTXT_DATE_ON_ADD"
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$OVR_TODOTXT_PRIORITY_ON_ADD" ] ; then
|
||||||
|
TODOTXT_PRIORITY_ON_ADD="$OVR_TODOTXT_PRIORITY_ON_ADD"
|
||||||
|
fi
|
||||||
if [ -n "$OVR_TODOTXT_DISABLE_FILTER" ] ; then
|
if [ -n "$OVR_TODOTXT_DISABLE_FILTER" ] ; then
|
||||||
TODOTXT_DISABLE_FILTER="$OVR_TODOTXT_DISABLE_FILTER"
|
TODOTXT_DISABLE_FILTER="$OVR_TODOTXT_DISABLE_FILTER"
|
||||||
fi
|
fi
|
||||||
@@ -761,6 +767,9 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
|||||||
[ -z "$ACTION" ] && usage
|
[ -z "$ACTION" ] && usage
|
||||||
[ -d "$TODO_DIR" ] || mkdir -p $TODO_DIR 2> /dev/null || dieWithHelp "$1" "Fatal Error: $TODO_DIR is not a directory"
|
[ -d "$TODO_DIR" ] || mkdir -p $TODO_DIR 2> /dev/null || dieWithHelp "$1" "Fatal Error: $TODO_DIR is not a directory"
|
||||||
( cd "$TODO_DIR" ) || dieWithHelp "$1" "Fatal Error: Unable to cd to $TODO_DIR"
|
( cd "$TODO_DIR" ) || dieWithHelp "$1" "Fatal Error: Unable to cd to $TODO_DIR"
|
||||||
|
[ -z "$TODOTXT_PRIORITY_ON_ADD" ] \
|
||||||
|
|| echo "$TODOTXT_PRIORITY_ON_ADD" | grep -q "^[A-Z]$" \
|
||||||
|
|| die "TODOTXT_PRIORITY_ON_ADD should be a capital letter from A to Z (it is now \"$TODOTXT_PRIORITY_ON_ADD\")."
|
||||||
|
|
||||||
[ -f "$TODO_FILE" -o -c "$TODO_FILE" ] || > "$TODO_FILE"
|
[ -f "$TODO_FILE" -o -c "$TODO_FILE" ] || > "$TODO_FILE"
|
||||||
[ -f "$DONE_FILE" -o -c "$DONE_FILE" ] || > "$DONE_FILE"
|
[ -f "$DONE_FILE" -o -c "$DONE_FILE" ] || > "$DONE_FILE"
|
||||||
@@ -790,6 +799,11 @@ _addto() {
|
|||||||
now=$(date '+%Y-%m-%d')
|
now=$(date '+%Y-%m-%d')
|
||||||
input=$(echo "$input" | sed -e 's/^\(([A-Z]) \)\{0,1\}/\1'"$now /")
|
input=$(echo "$input" | sed -e 's/^\(([A-Z]) \)\{0,1\}/\1'"$now /")
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "$TODOTXT_PRIORITY_ON_ADD" ]]; then
|
||||||
|
if ! echo "$input" | grep -q '^([A-Z])'; then
|
||||||
|
input=$(echo -n "($TODOTXT_PRIORITY_ON_ADD) " ; echo "$input")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
echo "$input" >> "$file"
|
echo "$input" >> "$file"
|
||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
TASKNUM=$(sed -n '$ =' "$file")
|
TASKNUM=$(sed -n '$ =' "$file")
|
||||||
|
|||||||
Reference in New Issue
Block a user