Skip to content

Commit

Permalink
Merge branch 'master' into hyperupcall-shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Sep 30, 2024
2 parents de598c0 + a916aa9 commit cf5f521
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- [ ] Fork [the repository](https://github.com/todotxt/todo.txt-cli) and create your branch from `master`.
- [ ] If you've added code that should be tested, add tests!
- [ ] Ensure the test suite passes.
- [ ] Format your code with [ShellCheck](https://www.shellcheck.net/).
- [ ] Lint your code with [ShellCheck](https://www.shellcheck.net/).
- [ ] Include a human-readable description of what the pull request is trying to accomplish.
- [ ] Steps for the reviewer(s) on how they can manually QA the changes.
- [ ] Have a `fixes #XX` reference to the issue that this pull request fixes.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab

jobs:
test:
strategy:
matrix:
platform: [ubuntu-20.04, macos-11]
platform: [ubuntu-24.04, macos-14]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: make
- run: make dist
- run: make test
Expand Down
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
Loading

0 comments on commit cf5f521

Please sign in to comment.