From eee2f1d503eb14fc72c85057c3ce742f78aa2ac0 Mon Sep 17 00:00:00 2001 From: Wayne Walker Date: Sun, 19 Sep 2021 00:59:30 -0500 Subject: [PATCH] Fix issue #361 - add persistence for priority on completion, as an option defaulting to original behavior --- tests/t0000-config.sh | 2 +- tests/t2100-help.sh | 8 ++++---- tests/t2120-shorthelp.sh | 12 ++++++------ tests/t6000-completion.sh | 2 +- tests/t6050-completion-addons.sh | 2 +- tests/t8000-actions.sh | 2 +- tests/t9999-testsuite_example.sh | 2 +- todo.sh | 19 +++++++++++++++---- todo_completion | 2 +- 9 files changed, 31 insertions(+), 20 deletions(-) diff --git a/tests/t0000-config.sh b/tests/t0000-config.sh index 1aced0cb..376f5a9b 100755 --- a/tests/t0000-config.sh +++ b/tests/t0000-config.sh @@ -21,7 +21,7 @@ test_expect_success 'no config file' ' # All the below tests will output the usage message. cat > expect <>> todo.sh help | sed '/^ [A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Options: Built-in Actions: EOF test_todo_session 'verbose help output' <>> todo.sh -v help | sed '/^ [A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Options: Built-in Actions: EOF test_todo_session 'very verbose help output' <>> todo.sh -vv help | sed '/^ [A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Options: Environment variables: Built-in Actions: @@ -34,7 +34,7 @@ EOF make_action "foo" test_todo_session 'help output with custom action' <>> todo.sh -v help | sed '/^ [A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Options: Built-in Actions: Add-on Actions: diff --git a/tests/t2120-shorthelp.sh b/tests/t2120-shorthelp.sh index f0123b72..14d4d37d 100755 --- a/tests/t2120-shorthelp.sh +++ b/tests/t2120-shorthelp.sh @@ -11,7 +11,7 @@ This test covers the output of the -h option and the shorthelp action. # check for the section headers. test_todo_session '-h output' <>> todo.sh -h | sed '/^ [A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Actions: Actions can be added and overridden using scripts in the actions See "help" for more details. @@ -19,7 +19,7 @@ EOF test_todo_session 'shorthelp output' <>> todo.sh shorthelp | sed '/^ [A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Actions: Actions can be added and overridden using scripts in the actions See "help" for more details. @@ -28,7 +28,7 @@ EOF make_action "foo" test_todo_session 'shorthelp output with custom action' <>> todo.sh -v shorthelp | sed '/^ [A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Actions: Actions can be added and overridden using scripts in the actions Add-on Actions: @@ -48,7 +48,7 @@ export TODOTXT_GLOBAL_CFG_FILE=global.cfg test_todo_session '-h and fatal error without config' <>> todo.sh -h | sed '/^ \\{0,2\\}[A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Actions: Actions can be added and overridden using scripts in the actions See "help" for more details. @@ -59,7 +59,7 @@ EOF # Config option comes too late; "Add-on Actions" is *not* mentioned here. test_todo_session '-h and fatal error with trailing custom config' <>> todo.sh -h -d custom.cfg | sed '/^ \\{0,2\\}[A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Actions: Actions can be added and overridden using scripts in the actions See "help" for more details. @@ -70,7 +70,7 @@ EOF # Config option processed; "Add-on Actions" is mentioned here. test_todo_session '-h output with preceding custom config' <>> todo.sh -d custom.cfg -h | sed '/^ \\{0,2\\}[A-Z]/!d' - Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] + Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Actions: Actions can be added and overridden using scripts in the actions Add-on Actions: diff --git a/tests/t6000-completion.sh b/tests/t6000-completion.sh index 61cf5948..ee573753 100755 --- a/tests/t6000-completion.sh +++ b/tests/t6000-completion.sh @@ -7,7 +7,7 @@ This test checks basic todo_completion of actions and options . ./test-lib.sh readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listaddons listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp' -readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x' +readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -m -n -t -v -vv -V -x' test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $OPTIONS" test_todo_completion 'arguments beginning with a' 'todo.sh a' 'add a addto addm append app archive' diff --git a/tests/t6050-completion-addons.sh b/tests/t6050-completion-addons.sh index 79ed0f19..86770c63 100755 --- a/tests/t6050-completion-addons.sh +++ b/tests/t6050-completion-addons.sh @@ -7,7 +7,7 @@ This test checks todo_completion of custom actions in .todo.actions.d . ./test-lib.sh readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listaddons listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp' -readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x' +readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -m -n -t -v -vv -V -x' readonly ADDONS='bar baz foobar' diff --git a/tests/t8000-actions.sh b/tests/t8000-actions.sh index 763c4e92..07aa1e5e 100755 --- a/tests/t8000-actions.sh +++ b/tests/t8000-actions.sh @@ -21,7 +21,7 @@ if [ -x .todo.actions.d/foo ]; then fi test_todo_session 'nonexecutable action' <>> todo.sh foo -Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] +Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Try 'todo.sh -h' for more information. === 1 EOF diff --git a/tests/t9999-testsuite_example.sh b/tests/t9999-testsuite_example.sh index ef25884e..7e80d9b3 100755 --- a/tests/t9999-testsuite_example.sh +++ b/tests/t9999-testsuite_example.sh @@ -159,7 +159,7 @@ TODO: 6 of 6 tasks shown TODO: 6 of 6 tasks shown >>> todo.sh remdup -Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] +Usage: todo.sh [-fhpamntvV] [-d todo_config] action [task_number] [task_description] Try 'todo.sh -h' for more information. === 1 EOF diff --git a/todo.sh b/todo.sh index fb8d4bce..f67d2ab1 100755 --- a/todo.sh +++ b/todo.sh @@ -24,7 +24,7 @@ TODO_SH=$(basename "$0") TODO_FULL_SH="$0" export TODO_SH TODO_FULL_SH -oneline_usage="$TODO_SH [-fhpantvV] [-d todo_config] action [task_number] [task_description]" +oneline_usage="$TODO_SH [-fhpamntvV] [-d todo_config] action [task_number] [task_description]" usage() { @@ -113,6 +113,8 @@ $indentedJoinedConfigFileLocations Don't auto-archive tasks automatically on completion -A Auto-archive tasks automatically on completion + -m + Maintain priority field on completion -n Don't preserve line numbers; automatically remove blank lines on task deletion @@ -142,6 +144,7 @@ $indentedJoinedConfigFileLocations TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE TODOTXT_FORCE=1 is same as option -f TODOTXT_PRESERVE_LINE_NUMBERS is same as option -n (0)/-N (1) + TODOTXT_PRESERVE_PRIORITY=1 is same as option -m TODOTXT_PLAIN is same as option -p (1)/-c (0) TODOTXT_DATE_ON_ADD is same as option -t (1)/-T (0) TODOTXT_PRIORITY_ON_ADD=pri default priority A-Z @@ -510,6 +513,7 @@ uppercasePriority() #Preserving environment variables so they don't get clobbered by the config file OVR_TODOTXT_AUTO_ARCHIVE="$TODOTXT_AUTO_ARCHIVE" OVR_TODOTXT_FORCE="$TODOTXT_FORCE" +OVR_TODOTXT_PRESERVE_PRIORITY="$TODOTXT_PRESERVE_PRIORITY" OVR_TODOTXT_PRESERVE_LINE_NUMBERS="$TODOTXT_PRESERVE_LINE_NUMBERS" OVR_TODOTXT_PLAIN="$TODOTXT_PLAIN" OVR_TODOTXT_DATE_ON_ADD="$TODOTXT_DATE_ON_ADD" @@ -524,7 +528,7 @@ OVR_TODOTXT_FINAL_FILTER="$TODOTXT_FINAL_FILTER" export GREP_OPTIONS="" # == PROCESS OPTIONS == -while getopts ":fhpcnNaAtTvVx+@Pd:" Option +while getopts ":fhpcmnNaAtTvVx+@Pd:" Option do case $Option in '@') @@ -581,7 +585,10 @@ do set -- '-h' 'shorthelp' OPTIND=2 ;; - n) + m ) + OVR_TODOTXT_PRESERVE_PRIORITY=1 + ;; + n ) OVR_TODOTXT_PRESERVE_LINE_NUMBERS=0 ;; N) @@ -632,6 +639,7 @@ shift $((OPTIND - 1)) TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1} TODOTXT_PLAIN=${TODOTXT_PLAIN:-0} TODOTXT_FORCE=${TODOTXT_FORCE:-0} +TODOTXT_PRESERVE_PRIORITY=${TODOTXT_PRESERVE_PRIORITY:-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} @@ -738,6 +746,9 @@ fi if [ -n "$OVR_TODOTXT_FORCE" ] ; then TODOTXT_FORCE="$OVR_TODOTXT_FORCE" fi +if [ -n "$OVR_TODOTXT_PRESERVE_PRIORITY" ] ; then + TODOTXT_PRESERVE_PRIORITY="$OVR_TODOTXT_PRESERVE_PRIORITY" +fi if [ -n "$OVR_TODOTXT_PRESERVE_LINE_NUMBERS" ] ; then TODOTXT_PRESERVE_LINE_NUMBERS="$OVR_TODOTXT_PRESERVE_LINE_NUMBERS" fi @@ -1231,7 +1242,7 @@ case $action in if [ "${todo:0:2}" != "x " ]; then now=$(date '+%Y-%m-%d') # remove priority once item is done - sed -i.bak "${item}s/^(.) //" "$TODO_FILE" + [[ "$TODOTXT_PRESERVE_PRIORITY" = "1" ]] || sed -i.bak $item"s/^(.) //" "$TODO_FILE" sed -i.bak "${item}s|^|x $now |" "$TODO_FILE" if [ "$TODOTXT_VERBOSE" -gt 0 ]; then getNewtodo "$item" diff --git a/todo_completion b/todo_completion index b285a63d..bfdf631d 100755 --- a/todo_completion +++ b/todo_completion @@ -10,7 +10,7 @@ _todo() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - local -r OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x" + local -r OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -m -n -t -v -vv -V -x" local -r COMMANDS="\ add a addto addm append app archive command del \ rm depri dp do help list ls listaddons listall lsa listcon \