Skip to content

Commit

Permalink
Finally integrate various features and fixes from inkarkat
Browse files Browse the repository at this point in the history
Merge pull request #405 from inkarkat/master
  • Loading branch information
inkarkat authored Sep 21, 2024
2 parents fd753c6 + ca444e4 commit 401653f
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ clean: test-pre-clean

install: installdirs
$(INSTALL_PROGRAM) todo.sh $(DESTDIR)$(bindir)/todo.sh
$(INSTALL_DATA) todo_completion $(DESTDIR)$(datarootdir)/todo
$(INSTALL_DATA) todo_completion $(DESTDIR)$(datarootdir)/todo.sh
[ -e $(DESTDIR)$(sysconfdir)/todo/config ] || \
sed "s/^\(export[ \t]*TODO_DIR=\).*/\1~\/.todo/" todo.cfg > $(DESTDIR)$(sysconfdir)/todo/config

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ make test
*NOTE:* Makefile defaults to several default paths for installed files. Adjust to your system:

- `INSTALL_DIR`: PATH for executables (default /usr/local/bin)
- `CONFIG_DIR`: PATH for todo.txt config
- `CONFIG_DIR`: PATH for the todo.txt configuration template
- `BASH_COMPLETION`: PATH for autocompletion scripts (default to /etc/bash_completion.d)

```shell
Expand All @@ -58,6 +58,11 @@ make install CONFIG_DIR=/etc INSTALL_DIR=/usr/bin BASH_COMPLETION=/usr/share/bas
https://aur.archlinux.org/packages/todotxt/


## Configuration

No configuration is required; however, most users tweak the default settings (e.g. relocating the todo.txt directory to a subdirectory of the user's home directory, or onto a cloud drive (via the `TODO_DIR` variable)), modify the colors, add additional highlighting of projects, contexts, dates, and so on. A configuration template with a commented-out list of all available options is included.
It is recommended to _copy_ that template into one of the locations listed by `todo.sh help` on `-d CONFIG_FILE`, even if it is installed in the global configuration location (`/etc/todo/config`).

## Usage
```shell
todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Expand Down
48 changes: 30 additions & 18 deletions tests/actions-test-lib.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
#!/bin/bash

make_action()
make_dummy_action()
{
unset TODO_ACTIONS_DIR
[ -d .todo.actions.d ] || mkdir .todo.actions.d
cat > ".todo.actions.d/$1" <<EOF
local actionName; actionName="$(basename "${1:?}")"
cat > "$1" <<EOF
#!/bin/bash
[ "\$1" = "usage" ] && {
echo " $1 ITEM#[, ITEM#, ...] [TERM...]"
echo " This custom action does $1."
echo " $actionName ITEM#[, ITEM#, ...] [TERM...]"
echo " This custom action does $actionName."
echo ""
exit
}
echo "custom action $1"
echo "custom action $actionName$2"
EOF
chmod +x ".todo.actions.d/$1"
chmod +x "$1"
}

make_action()
{
unset TODO_ACTIONS_DIR
[ -d .todo.actions.d ] || mkdir .todo.actions.d
[ -z "$1" ] || make_dummy_action ".todo.actions.d/$1"
}

make_action_in_folder()
{
unset TODO_ACTIONS_DIR
[ -d .todo.actions.d ] || mkdir .todo.actions.d
mkdir ".todo.actions.d/$1"
cat > ".todo.actions.d/$1/$1" <<EOF
#!/bin/bash
[ "\$1" = "usage" ] && {
echo " $1 ITEM#[, ITEM#, ...] [TERM...]"
echo " This custom action does $1."
echo ""
exit
[ -z "$1" ] || make_dummy_action ".todo.actions.d/$1/$1" "in folder $1"
}
echo "custom action $1 in folder $1"
EOF
chmod +x ".todo.actions.d/$1/$1"

invalidate_action()
{
local customActionFilespec="${1:?}"; shift
local testName="${1:?}"; shift

chmod -x "$customActionFilespec"
# On Cygwin, clearing the executable flag may have no effect, as the Windows
# ACL may still grant execution rights. In this case, we skip the test, and
# remove the (still valid) custom action so that it doesn't break following
# tests.
if [ -x "$customActionFilespec" ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }${testName}"
rm -- "$customActionFilespec"
fi
}
41 changes: 41 additions & 0 deletions tests/t1100-replace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ TODO: Replaced task with:
1 2010-07-04 this also has a new date
EOF

cat /dev/null > todo.txt
test_todo_session 'replace handling prepended priority on add' <<EOF
>>> todo.sh -t add "new task"
1 2009-02-13 new task
TODO: 1 added.
>>> todo.sh replace 1 '(B) this also has a priority now'
1 2009-02-13 new task
TODO: Replaced task with:
1 (B) 2009-02-13 this also has a priority now
EOF

cat /dev/null > todo.txt
test_todo_session 'replace handling priority and prepended date on add' <<EOF
>>> todo.sh -t add "new task"
Expand All @@ -156,6 +168,18 @@ TODO: Replaced task with:
1 (A) 2009-02-13 this is just a new one
EOF

cat /dev/null > todo.txt
test_todo_session 'replace handling prepended priority and date on add' <<EOF
>>> todo.sh -t add "new task"
1 2009-02-13 new task
TODO: 1 added.
>>> todo.sh replace 1 '(C) 2010-07-04 this also has a priority and new date'
1 2009-02-13 new task
TODO: Replaced task with:
1 (C) 2010-07-04 this also has a priority and new date
EOF

echo '(A) 2009-02-13 this is just a new one' > todo.txt
test_todo_session 'replace with prepended date replaces existing date' <<EOF
>>> todo.sh replace 1 2010-07-04 this also has a new date
Expand All @@ -164,6 +188,14 @@ TODO: Replaced task with:
1 (A) 2010-07-04 this also has a new date
EOF

echo '(A) 2009-02-13 this is just a new one' > todo.txt
test_todo_session 'replace with prepended priority replaces existing priority' <<EOF
>>> todo.sh replace 1 '(B) this also has a new priority'
1 (A) 2009-02-13 this is just a new one
TODO: Replaced task with:
1 (B) 2009-02-13 this also has a new priority
EOF

echo '2009-02-13 this is just a new one' > todo.txt
test_todo_session 'replace with prepended priority and date replaces existing date' <<EOF
>>> todo.sh replace 1 '(B) 2010-07-04 this also has a new date'
Expand All @@ -172,4 +204,13 @@ TODO: Replaced task with:
1 (B) 2010-07-04 this also has a new date
EOF


echo '(A) 2009-02-13 this is just a new one' > todo.txt
test_todo_session 'replace with prepended priority and date replaces existing priority and date' <<EOF
>>> todo.sh replace 1 '(B) 2010-07-04 this also has a new prio+date'
1 (A) 2009-02-13 this is just a new one
TODO: Replaced task with:
1 (B) 2010-07-04 this also has a new prio+date
EOF

test_done
1 change: 1 addition & 0 deletions tests/t1200-pri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ TODO: 2 re-prioritized from (C) to (A).
TODO: 3 of 3 tasks shown
>>> todo.sh pri 2 a
=== 1
2 (A) notice the sunflowers
TODO: 2 already prioritized (A).
Expand Down
20 changes: 20 additions & 0 deletions tests/t1250-listpri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ TODO: 0 of 5 tasks shown
--
TODO: 1 of 5 tasks shown
EOF
test_todo_session 'listpri filtering concatenation of priorities and -ranges' <<EOF
>>> todo.sh -p listpri CX
3 (C) notice the sunflowers
2 (X) clean the house from A-Z
4 (X) listen to music
--
TODO: 3 of 5 tasks shown
>>> todo.sh -p listpri ABR-Y
1 (B) smell the uppercase Roses +flowers @outside
2 (X) clean the house from A-Z
4 (X) listen to music
--
TODO: 3 of 5 tasks shown
>>> todo.sh -p listpri A-
2 (X) clean the house from A-Z
--
TODO: 1 of 5 tasks shown
EOF

cat > todo.txt <<EOF
(B) ccc xxx this line should be third.
Expand Down
1 change: 1 addition & 0 deletions tests/t1500-do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ test_todo_session 'fail multiple do attempts' <<EOF
TODO: 3 marked as done.
>>> todo.sh -a do 3
=== 1
TODO: 3 is already marked done.
EOF

Expand Down
1 change: 1 addition & 0 deletions tests/t1700-depri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ test_todo_session 'depriority of unprioritized task' <<EOF
TODO: 3 of 3 tasks shown
>>> todo.sh depri 3 2
=== 1
TODO: 3 is not prioritized.
2 notice the sunflowers
TODO: 2 deprioritized.
Expand Down
11 changes: 7 additions & 4 deletions tests/t1800-del.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ test_todo_session 'del with confirmation' <<EOF
TODO: 3 of 3 tasks shown
>>> printf n | todo.sh del 1
Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE
\\
TODO: No tasks were deleted.
=== 1
>>> todo.sh -p list
2 (A) notice the sunflowers
Expand All @@ -71,15 +72,17 @@ TODO: No tasks were deleted.
TODO: 3 of 3 tasks shown
>>> printf x | todo.sh del 1
Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE
\\
TODO: No tasks were deleted.
=== 1
>>> echo | todo.sh del 1
Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE
\\
TODO: No tasks were deleted.
=== 1
>>> printf y | todo.sh del 1
Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE
\\
1 (B) smell the uppercase Roses +flowers @outside
TODO: 1 deleted.
Expand Down
4 changes: 1 addition & 3 deletions tests/t1850-move.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ test_description='basic move functionality
'
. ./test-lib.sh

SPACE=' '

cat > todo.txt <<EOF
(B) smell the uppercase Roses +flowers @outside
(A) notice the sunflowers
Expand Down Expand Up @@ -42,7 +40,7 @@ x 2009-02-13 smell the coffee +wakeup
EOF
test_todo_session 'basic move with confirmation' <<EOF
>>> printf y | todo.sh move 1 done.txt 2>&1 | sed -e "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g" -e 's#from .\{1,\}/\([^/]\{1,\}\) to .\{1,\}/\([^/]\{1,\}\)?#from \1 to \2?#g'
Move '(B) smell the uppercase Roses +flowers @outside' from todo.txt to done.txt? (y/n)$SPACE
\\
1 (B) smell the uppercase Roses +flowers @outside
TODO: 1 moved from 'todo.txt' to 'done.txt'.
Expand Down
1 change: 1 addition & 0 deletions tests/t1910-deduplicate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ EOF

test_todo_session 'deduplicate without duplicates' <<EOF
>>> todo.sh deduplicate
=== 1
TODO: No duplicate tasks found
EOF

Expand Down
6 changes: 3 additions & 3 deletions tests/t2120-shorthelp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ echo 'export TODO_ACTIONS_DIR=$HOME/custom.actions' >> custom.cfg
export TODOTXT_GLOBAL_CFG_FILE=global.cfg

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]
Actions:
Actions can be added and overridden using scripts in the actions
Expand All @@ -58,7 +58,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' <<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]
Actions:
Actions can be added and overridden using scripts in the actions
Expand All @@ -69,7 +69,7 @@ EOF

# Config option processed; "Add-on Actions" is mentioned here.
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]
Actions:
Actions can be added and overridden using scripts in the actions
Expand Down
46 changes: 46 additions & 0 deletions tests/t8000-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,50 @@ custom action bad
=== 42
EOF

make_action
ln -s /actionsdir/doesnotexist/badlink .todo.actions.d/badlink
# On Cygwin, the Windows ACL may still grant execution rights. In this case, we
# skip the test.
if [ -x .todo.actions.d/badlink ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.6 t8000.7"
fi
test_todo_session 'broken symlink' <<EOF
>>> todo.sh badlink 2>&1 | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g"
Fatal Error: Broken link to custom action: '.todo.actions.d/badlink'
>>> todo.sh do 2>/dev/null
=== 1
EOF

make_action
mkdir .todo.actions.d/badfolderlink
ln -s /actionsdir/doesnotexist/badfolderlink .todo.actions.d/badfolderlink/badfolderlink
# On Cygwin, the Windows ACL may still grant execution rights. In this case, we
# skip the test.
if [ -x .todo.actions.d/badfolderlink/badfolderlink ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.8 t8000.9"
fi
test_todo_session 'broken symlink in folder' <<EOF
>>> 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'
>>> todo.sh do 2>/dev/null
=== 1
EOF

make_action
ln -s /actionsdir/doesnotexist/do .todo.actions.d/do
# On Cygwin, the Windows ACL may still grant execution rights. In this case, we
# skip the test.
if [ -x .todo.actions.d/do ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.10 t8000.11"
fi
test_todo_session 'broken symlink overrides built-in action' <<EOF
>>> todo.sh do 2>&1 | sed "s#'[^']*\(\\.todo\\.actions\\.d/[^']\{1,\}\)'#'\1'#g"
Fatal Error: Broken link to custom action: '.todo.actions.d/do'
>>> todo.sh do 2>/dev/null
=== 1
EOF

test_done
15 changes: 2 additions & 13 deletions tests/t8010-listaddons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ ls
quux
EOF

chmod -x .todo.actions.d/foo
# On Cygwin, clearing the executable flag may have no effect, as the Windows ACL
# may still grant execution rights. In this case, we skip the test.
if [ -x .todo.actions.d/foo ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8010.4"
fi
invalidate_action .todo.actions.d/foo t8010.4
test_todo_session 'nonexecutable action' <<EOF
>>> todo.sh listaddons
bar
Expand Down Expand Up @@ -66,13 +61,7 @@ norris
quux
EOF

# nthorne: shamelessly stolen from above..
chmod -x .todo.actions.d/norris/norris
# On Cygwin, clearing the executable flag may have no effect, as the Windows ACL
# may still grant execution rights. In this case, we skip the test.
if [ -x .todo.actions.d/norris/norris ]; then
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8010.8"
fi
invalidate_action .todo.actions.d/norris/norris t8010.8
test_todo_session 'nonexecutable action in subfolder' <<EOF
>>> todo.sh listaddons
bar
Expand Down
7 changes: 7 additions & 0 deletions todo.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export REPORT_FILE="$TODO_DIR/report.txt"

# === BEHAVIOR ===

## verbosity
#
# By default, additional information and confirmation of actions (like
# "TODO: 1 added") are printed. You can suppress this via 0 or add extra
# verbosity via 2.
# export TODOTXT_VERBOSE=1

## customize list output
#
# TODOTXT_SORT_COMMAND will filter after line numbers are
Expand Down
Loading

0 comments on commit 401653f

Please sign in to comment.