Merge branch 'fix/stderr'

This commit is contained in:
Ingo Karkat
2023-01-21 19:51:40 +01:00
8 changed files with 36 additions and 18 deletions

View File

@@ -90,6 +90,7 @@ TODO: 2 re-prioritized from (C) to (A).
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 a >>> todo.sh pri 2 a
=== 1
2 (A) notice the sunflowers 2 (A) notice the sunflowers
TODO: 2 already prioritized (A). TODO: 2 already prioritized (A).

View File

@@ -81,6 +81,7 @@ test_todo_session 'fail multiple do attempts' <<EOF
TODO: 3 marked as done. TODO: 3 marked as done.
>>> todo.sh -a do 3 >>> todo.sh -a do 3
=== 1
TODO: 3 is already marked done. TODO: 3 is already marked done.
EOF EOF

View File

@@ -82,6 +82,7 @@ test_todo_session 'depriority of unprioritized task' <<EOF
TODO: 3 of 3 tasks shown TODO: 3 of 3 tasks shown
>>> todo.sh depri 3 2 >>> todo.sh depri 3 2
=== 1
TODO: 3 is not prioritized. TODO: 3 is not prioritized.
2 notice the sunflowers 2 notice the sunflowers
TODO: 2 deprioritized. TODO: 2 deprioritized.

View File

@@ -4,6 +4,8 @@ test_description='basic del functionality
' '
. ./test-lib.sh . ./test-lib.sh
SPACE=' '
test_todo_session 'del usage' <<EOF test_todo_session 'del usage' <<EOF
>>> todo.sh del B >>> todo.sh del B
usage: todo.sh del ITEM# [TERM] usage: todo.sh del ITEM# [TERM]
@@ -60,6 +62,7 @@ TODO: 3 of 3 tasks shown
>>> printf n | todo.sh del 1 >>> printf n | todo.sh del 1
\\ \\
TODO: No tasks were deleted. TODO: No tasks were deleted.
=== 1
>>> todo.sh -p list >>> todo.sh -p list
2 (A) notice the sunflowers 2 (A) notice the sunflowers
@@ -71,10 +74,12 @@ TODO: 3 of 3 tasks shown
>>> printf x | todo.sh del 1 >>> printf x | todo.sh del 1
\\ \\
TODO: No tasks were deleted. TODO: No tasks were deleted.
=== 1
>>> echo | todo.sh del 1 >>> echo | todo.sh del 1
\\ \\
TODO: No tasks were deleted. TODO: No tasks were deleted.
=== 1
>>> printf y | todo.sh del 1 >>> printf y | todo.sh del 1
\\ \\

View File

@@ -32,6 +32,7 @@ EOF
test_todo_session 'deduplicate without duplicates' <<EOF test_todo_session 'deduplicate without duplicates' <<EOF
>>> todo.sh deduplicate >>> todo.sh deduplicate
=== 1
TODO: No duplicate tasks found TODO: No duplicate tasks found
EOF EOF

View File

@@ -47,7 +47,7 @@ echo 'export TODO_ACTIONS_DIR=$HOME/custom.actions' >> custom.cfg
export TODOTXT_GLOBAL_CFG_FILE=global.cfg export TODOTXT_GLOBAL_CFG_FILE=global.cfg
test_todo_session '-h and fatal error without config' <<EOF test_todo_session '-h and fatal error without config' <<EOF
>>> todo.sh -h | sed '/^ \\{0,2\\}[A-Z]/!d' >>> todo.sh -h 2>&1 | sed '/^ \\{0,2\\}[A-Z]/!d'
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Actions: Actions:
Actions can be added and overridden using scripts in the actions Actions can be added and overridden using scripts in the actions
@@ -58,7 +58,7 @@ EOF
# Config option comes too late; "Add-on Actions" is *not* mentioned here. # Config option comes too late; "Add-on Actions" is *not* mentioned here.
test_todo_session '-h and fatal error with trailing custom config' <<EOF test_todo_session '-h and fatal error with trailing custom config' <<EOF
>>> todo.sh -h -d custom.cfg | sed '/^ \\{0,2\\}[A-Z]/!d' >>> todo.sh -h -d custom.cfg 2>&1 | sed '/^ \\{0,2\\}[A-Z]/!d'
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Actions: Actions:
Actions can be added and overridden using scripts in the actions Actions can be added and overridden using scripts in the actions
@@ -69,7 +69,7 @@ EOF
# Config option processed; "Add-on Actions" is mentioned here. # Config option processed; "Add-on Actions" is mentioned here.
test_todo_session '-h output with preceding custom config' <<EOF test_todo_session '-h output with preceding custom config' <<EOF
>>> todo.sh -d custom.cfg -h | sed '/^ \\{0,2\\}[A-Z]/!d' >>> todo.sh -d custom.cfg -h 2>&1 | sed '/^ \\{0,2\\}[A-Z]/!d'
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Actions: Actions:
Actions can be added and overridden using scripts in the actions Actions can be added and overridden using scripts in the actions

View File

@@ -52,10 +52,10 @@ if [ -x .todo.actions.d/badlink ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.6 t8000.7" SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.6 t8000.7"
fi fi
test_todo_session 'broken symlink' <<EOF test_todo_session 'broken symlink' <<EOF
>>> todo.sh badlink | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g" >>> todo.sh badlink 2>&1 | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g"
Fatal Error: Broken link to custom action: '.todo.actions.d/badlink' Fatal Error: Broken link to custom action: '.todo.actions.d/badlink'
>>> todo.sh do >/dev/null >>> todo.sh do 2>/dev/null
=== 1 === 1
EOF EOF
@@ -68,10 +68,10 @@ if [ -x .todo.actions.d/badfolderlink/badfolderlink ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.8 t8000.9" SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.8 t8000.9"
fi fi
test_todo_session 'broken symlink in folder' <<EOF test_todo_session 'broken symlink in folder' <<EOF
>>> todo.sh badfolderlink | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g" >>> todo.sh badfolderlink 2>&1 | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g"
Fatal Error: Broken link to custom action: '.todo.actions.d/badfolderlink/badfolderlink' Fatal Error: Broken link to custom action: '.todo.actions.d/badfolderlink/badfolderlink'
>>> todo.sh do >/dev/null >>> todo.sh do 2>/dev/null
=== 1 === 1
EOF EOF
@@ -83,10 +83,10 @@ if [ -x .todo.actions.d/do ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.10 t8000.11" SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.10 t8000.11"
fi fi
test_todo_session 'broken symlink overrides built-in action' <<EOF test_todo_session 'broken symlink overrides built-in action' <<EOF
>>> todo.sh do | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g" >>> todo.sh do 2>&1 | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g"
Fatal Error: Broken link to custom action: '.todo.actions.d/do' Fatal Error: Broken link to custom action: '.todo.actions.d/do'
>>> todo.sh do >/dev/null >>> todo.sh do 2>/dev/null
=== 1 === 1
EOF EOF

27
todo.sh
View File

@@ -349,14 +349,14 @@ dieWithHelp()
case "$1" in case "$1" in
help) help;; help) help;;
shorthelp) shorthelp;; shorthelp) shorthelp;;
esac esac >&2
shift shift
die "$@" die "$@"
} }
die() die()
{ {
echo "$*" echo >&2 "$*"
exit 1 exit 1
} }
@@ -1182,7 +1182,7 @@ case $action in
echo "TODO: $item deleted." echo "TODO: $item deleted."
fi fi
else else
echo "TODO: No tasks were deleted." die "TODO: No tasks were deleted."
fi fi
else else
sed -i.bak \ sed -i.bak \
@@ -1212,6 +1212,7 @@ case $action in
# Split multiple depri's, if comma separated change to whitespace separated # Split multiple depri's, if comma separated change to whitespace separated
# Loop the 'depri' function for each item # Loop the 'depri' function for each item
status=0
for item in ${*//,/ }; do for item in ${*//,/ }; do
getTodo "$item" getTodo "$item"
@@ -1223,9 +1224,11 @@ case $action in
echo "TODO: $item deprioritized." echo "TODO: $item deprioritized."
fi fi
else else
echo "TODO: $item is not prioritized." echo >&2 "TODO: $item is not prioritized."
status=1
fi fi
done done
exit $status
;; ;;
"do" | "done" ) "do" | "done" )
@@ -1236,6 +1239,7 @@ case $action in
# Split multiple do's, if comma separated change to whitespace separated # Split multiple do's, if comma separated change to whitespace separated
# Loop the 'do' function for each item # Loop the 'do' function for each item
status=0
for item in ${*//,/ }; do for item in ${*//,/ }; do
getTodo "$item" getTodo "$item"
@@ -1251,15 +1255,17 @@ case $action in
echo "TODO: $item marked as done." echo "TODO: $item marked as done."
fi fi
else else
echo "TODO: $item is already marked done." echo >&2 "TODO: $item is already marked done."
status=1
fi fi
done done
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
# Recursively invoke the script to allow overriding of the archive # Recursively invoke the script to allow overriding of the archive
# action. # action.
"$TODO_FULL_SH" archive "$TODO_FULL_SH" archive || status=$?
fi fi
exit $status
;; ;;
"help" ) "help" )
@@ -1375,7 +1381,7 @@ case $action in
echo "TODO: $item moved from '$src' to '$dest'." echo "TODO: $item moved from '$src' to '$dest'."
fi fi
else else
echo "TODO: No tasks moved." die "TODO: No tasks moved."
fi fi
;; ;;
@@ -1386,6 +1392,7 @@ case $action in
"pri" | "p" ) "pri" | "p" )
shift shift
status=0
while [ "$#" -gt 0 ] ; do while [ "$#" -gt 0 ] ; do
item=$1 item=$1
newpri=$( printf "%s\n" "$2" | tr '[:lower:]' '[:upper:]' ) newpri=$( printf "%s\n" "$2" | tr '[:lower:]' '[:upper:]' )
@@ -1417,10 +1424,12 @@ note: PRIORITY must be anywhere from A to Z."
fi fi
fi fi
if [ "$oldpri" = "$newpri" ]; then if [ "$oldpri" = "$newpri" ]; then
echo "TODO: $item already prioritized ($newpri)." echo >&2 "TODO: $item already prioritized ($newpri)."
status=1
fi fi
shift; shift shift; shift
done done
exit $status
;; ;;
"replace" ) "replace" )
@@ -1488,7 +1497,7 @@ note: PRIORITY must be anywhere from A to Z."
newTaskNum=$( sed -e '/./!d' "$TODO_FILE" | sed -n '$ =' ) newTaskNum=$( sed -e '/./!d' "$TODO_FILE" | sed -n '$ =' )
deduplicateNum=$(( originalTaskNum - newTaskNum )) deduplicateNum=$(( originalTaskNum - newTaskNum ))
if [ $deduplicateNum -eq 0 ]; then if [ $deduplicateNum -eq 0 ]; then
echo "TODO: No duplicate tasks found" die "TODO: No duplicate tasks found"
else else
echo "TODO: $deduplicateNum duplicate task(s) removed" echo "TODO: $deduplicateNum duplicate task(s) removed"
fi fi