From c9540122e6a4b7d696cfece386e8929557a05e43 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Fri, 27 Mar 2020 19:44:45 -0500 Subject: [PATCH 01/38] Create GitHub action to run tests (#296) * Create GitHub Action * Remove travis yml to move to github actions. * Update CI badge in README --- .github/workflows/blank.yml | 33 +++++++++++++++++++++++++++++++++ .travis.yml | 6 ------ README.md | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/blank.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml new file mode 100644 index 0000000..53623bb --- /dev/null +++ b/.github/workflows/blank.yml @@ -0,0 +1,33 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: make dist + run: make dist + + - name: make install + run: make dist + + - name: make test + run: make test + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3295211..0000000 --- a/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Note: "shell" would be more appropriate -language: python - -install: make dist && sudo make install - -script: make test diff --git a/README.md b/README.md index 79c0cca..b077149 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > A simple and extensible shell script for managing your todo.txt file. -[![Build Status](https://travis-ci.org/todotxt/todo.txt-cli.svg?branch=master)](https://travis-ci.org/todotxt/todo.txt-cli) +![CI](https://github.com/todotxt/todo.txt-cli/workflows/CI/badge.svg) [![GitHub issues](https://img.shields.io/github/issues/todotxt/todo.txt-cli.svg)](https://github.com/todotxt/todo.txt-cli/issues) [![GitHub forks](https://img.shields.io/github/forks/todotxt/todo.txt-cli.svg)](https://github.com/todotxt/todo.txt-cli/network) [![GitHub stars](https://img.shields.io/github/stars/todotxt/todo.txt-cli.svg)](https://github.com/todotxt/todo.txt-cli/stargazers) From 8901db8bddf19cfbd72c8f885b6ca3a919b1a5d9 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Fri, 27 Mar 2020 20:13:02 -0500 Subject: [PATCH 02/38] Add multiple environments (#298) --- .github/workflows/blank.yml | 33 --------------------------------- .github/workflows/tests.yml | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 33 deletions(-) delete mode 100644 .github/workflows/blank.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml deleted file mode 100644 index 53623bb..0000000 --- a/.github/workflows/blank.yml +++ /dev/null @@ -1,33 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - - name: make dist - run: make dist - - - name: make install - run: make dist - - - name: make test - run: make test - diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..66bad21 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,20 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v2 + - run: make + - run: make dist + - run: make test + From 34d31ef45a5bf9bcb7ce1e2b4faa9ab4b9a77f49 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Fri, 27 Mar 2020 21:32:29 -0500 Subject: [PATCH 03/38] Fix macOS 10.15 date test (#299) - In macOS 10.15, the `date` command adds a "-R" flag. This can be seen in the default error display. Since the flags have changed, the grep command to find which version of macOS date binary we have. Because of this change, we need to do our own check for macOS 10.15. - Remove windows from the github actions as this tool is not for Windows, currently. --- .github/workflows/tests.yml | 2 +- Makefile | 4 ++-- tests/test-lib.sh | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 66bad21..b6232ee 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: test: strategy: matrix: - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 diff --git a/Makefile b/Makefile index 828a90d..1386819 100644 --- a/Makefile +++ b/Makefile @@ -37,9 +37,9 @@ dist: $(DISTFILES) todo.sh cp -f $(DISTFILES) $(DISTNAME)/ sed -e 's/@DEV_VERSION@/'$(VERSION)'/' todo.sh > $(DISTNAME)/todo.sh chmod +x $(DISTNAME)/todo.sh - tar cf $(DISTNAME).tar $(DISTNAME)/ + tar cf $(DISTNAME).tar $(DISTNAME) gzip -f -9 $(DISTNAME).tar - zip -9r $(DISTNAME).zip $(DISTNAME)/ + tar cf $(DISTNAME).zip $(DISTNAME) rm -r $(DISTNAME) .PHONY: clean diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 79d58f8..d5a7ac8 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -495,11 +495,18 @@ test_init_todo () { #... if date --version 2>&1 | grep -q "GNU"; then DATE_STYLE=GNU + # on Mac OS X 10.15: + #date --version + #date: illegal option -- - + #usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... + # [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] + elif date --version 2>&1 | grep -q -e "-jnRu"; then + DATE_STYLE=Mac10.15 # on Mac OS X 10.5: #date --version #date: illegal option -- - #usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... - #[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] + # [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] elif date --version 2>&1 | grep -q -e "-jnu"; then DATE_STYLE=Mac10.5 # on Mac OS X 10.4: @@ -519,6 +526,13 @@ test_init_todo () { EOF chmod 755 bin/date ;; + Mac10.15) + cat > bin/date <<-EOF + #!/bin/sh + exec "$TODO_TEST_REAL_DATE" -j -f %s \$TODO_TEST_TIME \$@ + EOF + chmod 755 bin/date + ;; Mac10.5) cat > bin/date <<-EOF #!/bin/sh From 13b451b81d49f83d97c8d0471c9c6ae1785e9036 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Sun, 29 Mar 2020 10:27:43 -0500 Subject: [PATCH 04/38] Add support for macOS catalina date (#300) Co-authored-by: Benoit Sagols --- tests/test-lib.sh | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index d5a7ac8..18655bc 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -495,19 +495,12 @@ test_init_todo () { #... if date --version 2>&1 | grep -q "GNU"; then DATE_STYLE=GNU - # on Mac OS X 10.15: - #date --version - #date: illegal option -- - - #usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... - # [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] - elif date --version 2>&1 | grep -q -e "-jnRu"; then - DATE_STYLE=Mac10.15 # on Mac OS X 10.5: #date --version #date: illegal option -- - #usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... # [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] - elif date --version 2>&1 | grep -q -e "-jnu"; then + elif date --version 2>&1 | grep -q -e "-jnR\?u"; then DATE_STYLE=Mac10.5 # on Mac OS X 10.4: #date --version @@ -526,13 +519,6 @@ test_init_todo () { EOF chmod 755 bin/date ;; - Mac10.15) - cat > bin/date <<-EOF - #!/bin/sh - exec "$TODO_TEST_REAL_DATE" -j -f %s \$TODO_TEST_TIME \$@ - EOF - chmod 755 bin/date - ;; Mac10.5) cat > bin/date <<-EOF #!/bin/sh From 861ad5ec410661b7c83f3e70cd35ee737c2e4080 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sun, 29 Mar 2020 19:03:33 +0200 Subject: [PATCH 05/38] Fix/noeol (#295) * Handle missing EOL in todo.txt This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file. In _addto(), ensure a trailing newline via sed (taken from https://unix.stackexchange.com/a/31955/18876). Fixes #294 * Tests: Add basic coverage of move * Handle missing EOL in todo.txt for move, too This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file. * Refactoring: Extract fixMissingEndOfLine() * FIX: Compatibility: sed \+ multi not supported on MacOS Use the POSIX \{1,\} instead. Co-authored-by: Ali Karbassi --- tests/t1000-addlist.sh | 13 ++++++++ tests/t1850-move.sh | 74 ++++++++++++++++++++++++++++++++++++++++++ todo.sh | 8 +++++ 3 files changed, 95 insertions(+) create mode 100755 tests/t1850-move.sh diff --git a/tests/t1000-addlist.sh b/tests/t1000-addlist.sh index fad3f23..c20d257 100755 --- a/tests/t1000-addlist.sh +++ b/tests/t1000-addlist.sh @@ -110,4 +110,17 @@ TODO: 1 added. TODO: 1 of 1 tasks shown EOF +echo -n 'this is a first task without newline' > todo.txt +test_todo_session 'add to file without EOL' <>> todo.sh add "a second task" +2 a second task +TODO: 2 added. + +>>> todo.sh list +2 a second task +1 this is a first task without newline +-- +TODO: 2 of 2 tasks shown +EOF + test_done diff --git a/tests/t1850-move.sh b/tests/t1850-move.sh new file mode 100755 index 0000000..e9061d5 --- /dev/null +++ b/tests/t1850-move.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# + +test_description='basic move functionality +' +. ./test-lib.sh + +cat > todo.txt < done.txt <>> todo.sh -f move 1 done.txt | sed "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g" +1 (B) smell the uppercase Roses +flowers @outside +TODO: 1 moved from 'todo.txt' to 'done.txt'. + +>>> todo.sh -p ls +2 (A) notice the sunflowers +-- +TODO: 1 of 1 tasks shown + +>>> todo.sh -p listfile done.txt +3 (B) smell the uppercase Roses +flowers @outside +1 x 2009-02-13 make the coffee +wakeup +2 x 2009-02-13 smell the coffee +wakeup +-- +DONE: 3 of 3 tasks shown +EOF + +test_todo_session 'basic move with passed source' <>> todo.sh -f move 2 todo.txt done.txt | sed "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g" +2 x 2009-02-13 smell the coffee +wakeup +TODO: 2 moved from 'done.txt' to 'todo.txt'. + +>>> todo.sh -p ls +2 (A) notice the sunflowers +3 x 2009-02-13 smell the coffee +wakeup +-- +TODO: 2 of 2 tasks shown + +>>> todo.sh -p listfile done.txt +3 (B) smell the uppercase Roses +flowers @outside +1 x 2009-02-13 make the coffee +wakeup +-- +DONE: 2 of 2 tasks shown +EOF + +echo -n 'this is a first task without newline' > todo.txt +cat > done.txt <>> todo.sh -f move 2 todo.txt done.txt | sed "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g" +2 x 2009-02-13 smell the coffee +wakeup +TODO: 2 moved from 'done.txt' to 'todo.txt'. + +>>> todo.sh -p ls +1 this is a first task without newline +2 x 2009-02-13 smell the coffee +wakeup +-- +TODO: 2 of 2 tasks shown + +>>> todo.sh -p listfile done.txt +1 x 2009-02-13 make the coffee +wakeup +-- +DONE: 1 of 1 tasks shown +EOF + +test_done diff --git a/todo.sh b/todo.sh index df56640..bcfaf73 100755 --- a/todo.sh +++ b/todo.sh @@ -466,6 +466,12 @@ replaceOrPrepend() fi } +fixMissingEndOfLine() +{ + # Parameters: $1: todo file; empty means $TODO_FILE. + sed -i.bak -e '$a\' "${1:-$TODO_FILE}" +} + uppercasePriority() { # Precondition: $input contains task text for which to uppercase priority. @@ -809,6 +815,7 @@ _addto() { input=$(echo -n "($TODOTXT_PRIORITY_ON_ADD) " ; echo "$input") fi fi + fixMissingEndOfLine "$file" echo "$input" >> "$file" if [ "$TODOTXT_VERBOSE" -gt 0 ]; then TASKNUM=$(sed -n '$ =' "$file") @@ -1339,6 +1346,7 @@ case $action in # leave blank line behind (preserves line numbers) sed -i.bak -e "${item}s/^.*//" "$src" fi + fixMissingEndOfLine "$dest" echo "$todo" >> "$dest" if [ "$TODOTXT_VERBOSE" -gt 0 ]; then From 20317b6321cc1368f93a01f503ed3c0b7e49ed8b Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sun, 29 Mar 2020 19:27:25 +0200 Subject: [PATCH 06/38] Refactoring: Extract the many complex sed arguments into sedTransformations array and move the comments closer (#273) There's too much distance between the comments that describe the various transformations that are done on the referenced task, and the corresponding sed expressions. By using a local Bash array, we can collect the arguments and have the comments close by. Co-authored-by: Ali Karbassi --- todo_completion | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/todo_completion b/todo_completion index 644be6e..f26497b 100755 --- a/todo_completion +++ b/todo_completion @@ -48,23 +48,28 @@ _todo() completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listcon 2>/dev/null) ;; *) if [[ "$cur" =~ ^[0-9]+$ ]]; then - # Remove the (padded) task number; we prepend the - # user-provided $cur instead. - # Remove the timestamp prepended by the -t option, - # and the done date (for done tasks); there's no - # todo.txt option for that yet. - # But keep priority and "x"; they're short and may - # provide useful context. - # Remove any trailing whitespace; the Bash - # completion inserts a trailing space itself. - # Finally, limit the output to a single line just as - # a safety check of the ls action output. + declare -a sedTransformations=( + # Remove the (padded) task number; we prepend the + # user-provided $cur instead. + -e 's/^ *[0-9]\{1,\} //' + # Remove the timestamp prepended by the -t option, + # but keep any priority (as it's short and may + # provide useful context). + -e 's/^\((.) \)\{0,1\}[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' + # Remove the done date and (if there) the timestamp. + # Keep the "x" (as it's short and may provide useful + # context) + -e 's/^\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' + # Remove any trailing whitespace; the Bash + # completion inserts a trailing space itself. + -e 's/[[:space:]]*$//' + # Finally, limit the output to a single line just as + # a safety check of the ls action output. + -e '1q' + ) local todo=$( \ eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' 2>/dev/null | \ - sed -e 's/^ *[0-9]\{1,\} //' -e 's/^\((.) \)\{0,1\}[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' \ - -e 's/^\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \ - -e 's/[[:space:]]*$//' \ - -e '1q' \ + sed "${sedTransformations[@]}" \ ) # Append task text as a shell comment. This # completion can be a safety check before a From 355166da671404a06fc86a20f593ca9bda68042b Mon Sep 17 00:00:00 2001 From: Tiziano Zito Date: Sun, 29 Mar 2020 21:20:06 +0200 Subject: [PATCH 07/38] Highlighting of dates, metadata and item numbers (#264) * add highlighting of dates, item numbers, and metadata * add test for highlighting of dates, item numbers, and metadata Co-authored-by: Ali Karbassi --- ...80-ls-date-number-metadata-highlighting.sh | 45 +++++++++++++++++++ todo.cfg | 9 +++- todo.sh | 25 ++++++++++- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100755 tests/t1380-ls-date-number-metadata-highlighting.sh diff --git a/tests/t1380-ls-date-number-metadata-highlighting.sh b/tests/t1380-ls-date-number-metadata-highlighting.sh new file mode 100755 index 0000000..dcfc493 --- /dev/null +++ b/tests/t1380-ls-date-number-metadata-highlighting.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# + +test_description='highlighting date, item numbers and metadata + +This test checks the highlighting (with colors) of dates, item numbers and metadata +' +. ./test-lib.sh + +# Tasks with dates and metadata +cat > todo.txt < "$TEST_TODO_LABEL_COLORS" + +echo "export COLOR_DATE='\\\\033[0;31m'" >>"$TEST_TODO_LABEL_COLORS" +echo "export COLOR_META='\\\\033[0;32m'" >>"$TEST_TODO_LABEL_COLORS" +echo "export COLOR_NUMBER='\\\\033[0;34m'" >>"$TEST_TODO_LABEL_COLORS" + +test_todo_session 'highlighting for date, item numbers and metadata' <<'EOF' +>>> todo.sh -d "$TEST_TODO_LABEL_COLORS" ls +1 2018-11-11 task with date +2 task with metadata due:2018-12-31 +3 task without date and without metadata +-- +TODO: 3 of 3 tasks shown +EOF + + +test_todo_session 'suppressing highlighting for date, item numbers and metadata' <<'EOF' +>>> todo.sh -p -d "$TEST_TODO_LABEL_COLORS" ls +1 2018-11-11 task with date +2 task with metadata due:2018-12-31 +3 task without date and without metadata +-- +TODO: 3 of 3 tasks shown +EOF + +test_done diff --git a/todo.cfg b/todo.cfg index 6c6f867..886a533 100644 --- a/todo.cfg +++ b/todo.cfg @@ -62,10 +62,17 @@ export REPORT_FILE="$TODO_DIR/report.txt" # # export COLOR_DONE=$LIGHT_GREY -# There is highlighting for projects and contexts. +# There is highlighting for projects, contexts, dates, and item numbers. # # export COLOR_PROJECT=$RED # export COLOR_CONTEXT=$RED +# export COLOR_DATE=$BLUE +# export COLOR_NUMBER=$LIGHT_GRAY + +# There is highlighting for metadata key:value pairs e.g. +# DUE:2006-08-01 or note:MYNOTE +# +# export COLOR_META=$CYAN # === BEHAVIOR === diff --git a/todo.sh b/todo.sh index bcfaf73..53b85c7 100755 --- a/todo.sh +++ b/todo.sh @@ -650,9 +650,12 @@ export PRI_B=$GREEN # color for B priority export PRI_C=$LIGHT_BLUE # color for C priority export PRI_X=$WHITE # color unless explicitly defined -# Default project and context colors. +# Default project, context, date, item number, and metadata key:value pairs colors. export COLOR_PROJECT=$NONE export COLOR_CONTEXT=$NONE +export COLOR_DATE=$NONE +export COLOR_NUMBER=$NONE +export COLOR_META=$NONE # Default highlight colors. export COLOR_DONE=$LIGHT_GREY # color for done (but not yet archived) tasks @@ -795,6 +798,9 @@ if [ $TODOTXT_PLAIN = 1 ]; then COLOR_DONE=$NONE COLOR_PROJECT=$NONE COLOR_CONTEXT=$NONE + COLOR_DATE=$NONE + COLOR_NUMBER=$NONE + COLOR_META=$NONE fi [[ "$HIDE_PROJECTS_SUBSTITUTION" ]] && COLOR_PROJECT="$NONE" @@ -971,15 +977,30 @@ _format() ctx_beg = highlight("COLOR_CONTEXT") ctx_end = (ctx_beg ? (highlight("DEFAULT") clr) : "") + dat_beg = highlight("COLOR_DATE") + dat_end = (dat_beg ? (highlight("DEFAULT") clr) : "") + + num_beg = highlight("COLOR_NUMBER") + num_end = (num_beg ? (highlight("DEFAULT") clr) : "") + + met_beg = highlight("COLOR_META") + met_end = (met_beg ? (highlight("DEFAULT") clr) : "") + gsub(/[ \t][ \t]*/, "\n&\n") len = split($0, words, /\n/) printf "%s", clr for (i = 1; i <= len; ++i) { - if (words[i] ~ /^[+].*[A-Za-z0-9_]$/) { + if (i == 1 && words[i] ~ /^[0-9]+$/ ) { + printf "%s", num_beg words[i] num_end + } else if (words[i] ~ /^[+].*[A-Za-z0-9_]$/) { printf "%s", prj_beg words[i] prj_end } else if (words[i] ~ /^[@].*[A-Za-z0-9_]$/) { printf "%s", ctx_beg words[i] ctx_end + } else if (words[i] ~ /^(19|20)[0-9]{2}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/) { + printf "%s", dat_beg words[i] dat_end + } else if (words[i] ~ /^[[:alnum:]]+:[^ ]+$/) { + printf "%s", met_beg words[i] met_end } else { printf "%s", words[i] } From c6d290b5fb315ca4daeb436749d8cc800152bb09 Mon Sep 17 00:00:00 2001 From: LeLobster Date: Sun, 29 Mar 2020 21:29:40 +0200 Subject: [PATCH 08/38] Fix the Makefile to work with the install instructions in the README (#259) * Fix the Makefile to work with the install instructions in the README * Put back DEST_DIR * Add simple ifdef checks to see if the user has set custom dirs via the commandline * Update README to match Makefile --- Makefile | 23 +++++++++++++++++++---- README.md | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1386819..d2ceff2 100644 --- a/Makefile +++ b/Makefile @@ -10,13 +10,28 @@ INSTALL_DATA = $(INSTALL) -m 644 prefix = /usr/local +# ifdef check allows the user to pass custom dirs +# as per the README + # The directory to install todo.sh in. -bindir = $(prefix)/bin +ifdef INSTALL_DIR + bindir = $(INSTALL_DIR) +else + bindir = $(prefix)/bin +endif # The directory to install the config file in. -sysconfdir = $(prefix)/etc +ifdef CONFIG_DIR + sysconfdir = $(CONFIG_DIR) +else + sysconfdir = $(prefix)/etc +endif -datarootdir = $(prefix)/share +ifdef BASH_COMPLETION + datarootdir = $(BASH_COMPLETION) +else + datarootdir = $(prefix)/share +endif # Dynamically detect/generate version file as necessary # This file will define a variable called VERSION. @@ -85,4 +100,4 @@ test: aggregate-results rm -rf tests/test-results # Force tests to get run every time -.PHONY: test test-pre-clean aggregate-results $(TESTS) +.PHONY: test test-pre-clean aggregate-results $(TESTS) \ No newline at end of file diff --git a/README.md b/README.md index b077149..bda1a28 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ make test - `BASH_COMPLETION`: PATH for autocompletion scripts (default to /etc/bash_completion.d) ```shell -make install CONFIG_DIR=/etc INSTALL_DIR=/usr/bin BASH_COMPLETION_DIR=/usr/share/bash-completion/completions +make install CONFIG_DIR=/etc INSTALL_DIR=/usr/bin BASH_COMPLETION=/usr/share/bash-completion/completions ``` #### Arch Linux (AUR) From 3d308a6f79c3160f01e9ae4db3526d29aa6c09d6 Mon Sep 17 00:00:00 2001 From: 85 Date: Mon, 30 Mar 2020 02:33:16 +0700 Subject: [PATCH 09/38] Minimal config file / default filenames (todo.txt, done.txt, report.txt) (#289) * Set default files name * Add test for minimal config file --- tests/t0000-config.sh | 14 ++++++++++++++ todo.sh | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/tests/t0000-config.sh b/tests/t0000-config.sh index ac1af9f..90c05ce 100755 --- a/tests/t0000-config.sh +++ b/tests/t0000-config.sh @@ -79,4 +79,18 @@ test_expect_success 'config file (env variable)' ' test_cmp expect output && test -f used_config ' +cat > minimal.cfg << EOF +export TODO_DIR=. +touch used_config +EOF + +rm -f used_config +test_expect_success 'config file (minimal)' ' + mkdir .todo + cp minimal.cfg .todo/config + todo.sh > output; + test_cmp expect output && test -f used_config && + rm -rf .todo +' + test_done diff --git a/todo.sh b/todo.sh index 53b85c7..39a6ee3 100755 --- a/todo.sh +++ b/todo.sh @@ -785,6 +785,10 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION} || 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\")." +[ -z "$TODO_FILE" ] && TODO_FILE="$TODO_DIR/todo.txt" +[ -z "$DONE_FILE" ] && DONE_FILE="$TODO_DIR/done.txt" +[ -z "$REPORT_FILE" ] && REPORT_FILE="$TODO_DIR/report.txt" + [ -f "$TODO_FILE" ] || [ -c "$TODO_FILE" ] || > "$TODO_FILE" [ -f "$DONE_FILE" ] || [ -c "$DONE_FILE" ] || > "$DONE_FILE" [ -f "$REPORT_FILE" ] || [ -c "$REPORT_FILE" ] || > "$REPORT_FILE" From 1378c97d8023acdb4f0484da17f77718e5708b5c Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Sun, 29 Mar 2020 14:53:42 -0500 Subject: [PATCH 10/38] Allow setting of bash completion path (#301) Fixes #242 --- Makefile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d2ceff2..0bdcf74 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ endif ifdef BASH_COMPLETION datarootdir = $(BASH_COMPLETION) else - datarootdir = $(prefix)/share + datarootdir = $(prefix)/share/bash_completion.d endif # Dynamically detect/generate version file as necessary @@ -64,22 +64,22 @@ clean: test-pre-clean install: installdirs $(INSTALL_PROGRAM) todo.sh $(DESTDIR)$(bindir)/todo.sh - $(INSTALL_DATA) todo_completion $(DESTDIR)$(datarootdir)/bash_completion.d/todo + $(INSTALL_DATA) todo_completion $(DESTDIR)$(datarootdir)/todo [ -e $(DESTDIR)$(sysconfdir)/todo/config ] || \ sed "s/^\(export[ \t]*TODO_DIR=\).*/\1~\/.todo/" todo.cfg > $(DESTDIR)$(sysconfdir)/todo/config uninstall: rm -f $(DESTDIR)$(bindir)/todo.sh - rm -f $(DESTDIR)$(datarootdir)/bash_completion.d/todo + rm -f $(DESTDIR)$(datarootdir)/todo rm -f $(DESTDIR)$(sysconfdir)/todo/config - rmdir $(DESTDIR)$(datarootdir)/bash_completion.d + rmdir $(DESTDIR)$(datarootdir) rmdir $(DESTDIR)$(sysconfdir)/todo installdirs: mkdir -p $(DESTDIR)$(bindir) \ $(DESTDIR)$(sysconfdir)/todo \ - $(DESTDIR)$(datarootdir)/bash_completion.d + $(DESTDIR)$(datarootdir) # # Testing @@ -100,4 +100,5 @@ test: aggregate-results rm -rf tests/test-results # Force tests to get run every time -.PHONY: test test-pre-clean aggregate-results $(TESTS) \ No newline at end of file +.PHONY: test test-pre-clean aggregate-results $(TESTS) + From abdbe5371c4dd4b9e371a017d79fada23d2dca8b Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Sun, 29 Mar 2020 21:26:56 -0500 Subject: [PATCH 11/38] Clean up files (#302) --- CODE_OF_CONDUCT.md => .github/CODE_OF_CONDUCT.md | 0 CONTRIBUTING.md => .github/CONTRIBUTING.md | 2 +- ISSUE_TEMPLATE.md => .github/ISSUE_TEMPLATE.md | 0 PULL_REQUEST_TEMPLATE.md => .github/PULL_REQUEST_TEMPLATE.md | 0 CHANGELOG.md | 2 +- README.md | 4 ++-- 6 files changed, 4 insertions(+), 4 deletions(-) rename CODE_OF_CONDUCT.md => .github/CODE_OF_CONDUCT.md (100%) rename CONTRIBUTING.md => .github/CONTRIBUTING.md (99%) rename ISSUE_TEMPLATE.md => .github/ISSUE_TEMPLATE.md (100%) rename PULL_REQUEST_TEMPLATE.md => .github/PULL_REQUEST_TEMPLATE.md (100%) diff --git a/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md similarity index 100% rename from CODE_OF_CONDUCT.md rename to .github/CODE_OF_CONDUCT.md diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 99% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md index 415b49d..55b1d2c 100644 --- a/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -93,5 +93,5 @@ The core team looks at Pull Requests on a regular basis. After feedback has been You can chat with the core team on https://gitter.im/todotxt/. [todo.txt]: https://github.com/todotxt/ -[Code of Conduct]: /CODE_OF_CONDUCT.md +[Code of Conduct]: ./CODE_OF_CONDUCT.md [Gitter.im]: https://gitter.im/todotxt/ diff --git a/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md similarity index 100% rename from ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE.md diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 2035bfd..f997ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [2.11.0] - 2018-03-26 ### Added - Added support for `$XDG_CONFIG_HOME` config file/actions location -- Created [CODE_OF_CONDUCT.md](/CODE_OF_CONDUCT.md) ([#217]) +- Created [CODE_OF_CONDUCT.md](.github/CODE_OF_CONDUCT.md) ([#217]) - Created [CHANGELOG.md](/CHANGELOG.md) ([#218]) diff --git a/README.md b/README.md index bda1a28..15c6fed 100644 --- a/README.md +++ b/README.md @@ -95,5 +95,5 @@ GNU General Public License v3.0 © [todo.txt org][github] [github]: https://github.com/todotxt [USAGE]: ./USAGE.md [CHANGELOG]: ./CHANGELOG.md -[CODE_OF_CONDUCT]: ./CODE_OF_CONDUCT.md -[CONTRIBUTING]: ./CONTRIBUTING.md +[CODE_OF_CONDUCT]: .github/CODE_OF_CONDUCT.md +[CONTRIBUTING]: .github/CONTRIBUTING.md From 177432ec9433b226393443d0fdf571b2f61f1a6f Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 31 Mar 2020 00:44:50 +0200 Subject: [PATCH 12/38] ENH: Enable file completion for add-on actions via _todo_file{1,2,3}_actions (#270) * Refactoring: Use regular expression match instead of case globbing for actions taking a SRC argument Making it consistent with the test for MOVE_COMMAND_PATTERN, and allowing to extend the pattern with custom actions in the future. * Refactoring: Move the anchoring and grouping out of MOVE_COMMAND_PATTERN So that additional (custom) add-on actions can be configured in the future. * ENH: Enable file completion for add-on actions via _todo_file{1,2,3}_actions Allowing completion of todo files directly after the add-on action (1), with one (2) / two (3) arguments in between. This should handle most cases. In order to configure the add-on completion, the corresponding configuration variable has to be defined in the user's shell (e.g. via ~/.bashrc): _todo_file1_actions='myaction|anotheraction' --- tests/t6060-completion-addon-files.sh | 28 +++++++ todo_completion | 106 +++++++++++++------------- 2 files changed, 82 insertions(+), 52 deletions(-) create mode 100755 tests/t6060-completion-addon-files.sh diff --git a/tests/t6060-completion-addon-files.sh b/tests/t6060-completion-addon-files.sh new file mode 100755 index 0000000..94ad60e --- /dev/null +++ b/tests/t6060-completion-addon-files.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# + +test_description='Bash add-on action file completion functionality + +This test checks todo_completion of files for add-on actions that have file argument(s) configured +' +. ./test-lib.sh + +readonly FILES='done.txt report.txt todo.txt' +test_todo_completion 'nothing after unconfigured bar' 'todo.sh bar ' '' + +_todo_file1_actions='foo|bar' +test_todo_completion 'all files after configured bar' 'todo.sh bar ' "$FILES" +test_todo_completion 'nothing after configured bar ITEM#' 'todo.sh bar 1 ' '' + +_todo_file2_actions='baz' +test_todo_completion 'nothing after configured baz' 'todo.sh baz ' '' +test_todo_completion 'all files after configured baz ITEM#' 'todo.sh baz 1 ' "$FILES" +test_todo_completion 'nothing after configured baz ITEM# MORE' 'todo.sh baz 1 more ' '' + +_todo_file3_actions='biz' +test_todo_completion 'nothing after configured biz' 'todo.sh biz ' '' +test_todo_completion 'nothing after configured biz ITEM#' 'todo.sh biz 1 ' '' +test_todo_completion 'all files after configured biz ITEM# MORE' 'todo.sh biz 1 more ' "$FILES" +test_todo_completion 'nothing after configured biz ITEM# EVEN MORE' 'todo.sh biz 1 even more ' '' + +test_done diff --git a/todo_completion b/todo_completion index f26497b..b403a55 100755 --- a/todo_completion +++ b/todo_completion @@ -14,15 +14,15 @@ _todo() 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" - local -r MOVE_COMMAND_PATTERN='^(move|mv)$' + local -r MOVE_COMMAND_PATTERN='move|mv' local _todo_sh=${_todo_sh:-todo.sh} local completions if [ $COMP_CWORD -eq 1 ]; then completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons 2>/dev/null) $OPTS" elif [[ $COMP_CWORD -gt 2 && ( \ - "${COMP_WORDS[COMP_CWORD-2]}" =~ $MOVE_COMMAND_PATTERN || \ - "${COMP_WORDS[COMP_CWORD-3]}" =~ $MOVE_COMMAND_PATTERN ) ]]; then + "${COMP_WORDS[COMP_CWORD-2]}" =~ ^($MOVE_COMMAND_PATTERN${_todo_file2_actions:+|${_todo_file2_actions}})$ || \ + "${COMP_WORDS[COMP_CWORD-3]}" =~ ^($MOVE_COMMAND_PATTERN${_todo_file3_actions:+|${_todo_file3_actions}})$ ) ]]; then # "move ITEM# DEST [SRC]" has file arguments on positions 2 and 3. completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile 2>/dev/null) else @@ -31,56 +31,58 @@ _todo() completions=$COMMANDS;; help) completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons 2>/dev/null)";; - addto|listfile|lf) - completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile 2>/dev/null);; -*) completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons 2>/dev/null) $OPTS";; - *) case "$cur" in - +*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listproj 2>/dev/null) - COMPREPLY=( $( compgen -W "$completions" -- $cur )) - [ ${#COMPREPLY[@]} -gt 0 ] && return 0 - # Fall back to projects extracted from done tasks. - completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listproj 2>/dev/null) - ;; - @*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listcon 2>/dev/null) - COMPREPLY=( $( compgen -W "$completions" -- $cur )) - [ ${#COMPREPLY[@]} -gt 0 ] && return 0 - # Fall back to contexts extracted from done tasks. - completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listcon 2>/dev/null) - ;; - *) if [[ "$cur" =~ ^[0-9]+$ ]]; then - declare -a sedTransformations=( - # Remove the (padded) task number; we prepend the - # user-provided $cur instead. - -e 's/^ *[0-9]\{1,\} //' - # Remove the timestamp prepended by the -t option, - # but keep any priority (as it's short and may - # provide useful context). - -e 's/^\((.) \)\{0,1\}[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' - # Remove the done date and (if there) the timestamp. - # Keep the "x" (as it's short and may provide useful - # context) - -e 's/^\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' - # Remove any trailing whitespace; the Bash - # completion inserts a trailing space itself. - -e 's/[[:space:]]*$//' - # Finally, limit the output to a single line just as - # a safety check of the ls action output. - -e '1q' - ) - local todo=$( \ - eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' 2>/dev/null | \ - sed "${sedTransformations[@]}" \ - ) - # Append task text as a shell comment. This - # completion can be a safety check before a - # destructive todo.txt operation. - [ "$todo" ] && COMPREPLY[0]="$cur # $todo" - return 0 - else - return 0 - fi - ;; - esac + *) if [[ "$prev" =~ ^(addto|listfile|lf${_todo_file1_actions:+|${_todo_file1_actions}})$ ]]; then + completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile 2>/dev/null) + else + case "$cur" in + +*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listproj 2>/dev/null) + COMPREPLY=( $( compgen -W "$completions" -- $cur )) + [ ${#COMPREPLY[@]} -gt 0 ] && return 0 + # Fall back to projects extracted from done tasks. + completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listproj 2>/dev/null) + ;; + @*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listcon 2>/dev/null) + COMPREPLY=( $( compgen -W "$completions" -- $cur )) + [ ${#COMPREPLY[@]} -gt 0 ] && return 0 + # Fall back to contexts extracted from done tasks. + completions=$(eval 'TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE' $_todo_sh command listcon 2>/dev/null) + ;; + *) if [[ "$cur" =~ ^[0-9]+$ ]]; then + declare -a sedTransformations=( + # Remove the (padded) task number; we prepend the + # user-provided $cur instead. + -e 's/^ *[0-9]\{1,\} //' + # Remove the timestamp prepended by the -t option, + # but keep any priority (as it's short and may + # provide useful context). + -e 's/^\((.) \)\{0,1\}[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' + # Remove the done date and (if there) the timestamp. + # Keep the "x" (as it's short and may provide useful + # context) + -e 's/^\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' + # Remove any trailing whitespace; the Bash + # completion inserts a trailing space itself. + -e 's/[[:space:]]*$//' + # Finally, limit the output to a single line just as + # a safety check of the ls action output. + -e '1q' + ) + local todo=$( \ + eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' 2>/dev/null | \ + sed "${sedTransformations[@]}" \ + ) + # Append task text as a shell comment. This + # completion can be a safety check before a + # destructive todo.txt operation. + [ "$todo" ] && COMPREPLY[0]="$cur # $todo" + return 0 + else + return 0 + fi + ;; + esac + fi ;; esac fi From bf1bf1ae8423fffa395d70e79ba0385cdc4e1faf Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 31 Mar 2020 01:13:29 +0200 Subject: [PATCH 13/38] ENH: Allow to customize what can be before / inside / after +project and @context (#271) * ENH: Allow to customize what can be before / inside / after +project and @context I noticed that todo.sh mistakenly picks up some random stuff as projects and contexts. The todo.txt specification is very lenient in what makes those (allowing any length of non-whitespace characters), but in practice, every user has its own idea of the set of used words. This change allows (expert) users to tweak the pattern (via TODOTXT_SIGIL_VALID_PATTERN), to be able to reduce the amount of "false positives" that listproj and listcon show. Additionally, there's a (mainly unspecified) extension mechanism in the form of key:value, which often is used to implement custom "markers", like w:something to make a task blocked and waiting for "something". It would be nice to be able to refer to @contexts (and maybe also +projects), but the default syntax (which requires whitespace around those) doesn't allow it, and these context then don't show up in searches, which is unfortunate. The added TODOTXT_SIGIL_BEFORE_PATTERN and TODOTXT_SIGIL_AFTER_PATTERN allow to tweak the syntax to accommodate this. The implementation just exchanges grep with a corresponding sed pipeline step, which shouldn't negatively affect the performance at all (as sed is one of the main commands used thoughout the script), but which allows for the additional matching flexibility. * FIX: Compatibility: sed \? multi not supported on MacOS Use the POSIX \{0,1\} instead. * FIX: Compatibility: sed \| multi not supported on MacOS Concatenate both alternatives as optional matches; this is only an approximation but satisfies the test case here. It would probably be better if the entire sed code used extended regular expression syntax (-E) instead of basic ones (-e), but that change would also affect all add-ons. As this is an optional customization feature, uses who really need this either also have to work around, or supply a GNU sed port on MacOS. * FIX: Compatibility: sed \+ multi not supported on MacOS Use the POSIX \{1,\} instead. Co-authored-by: Ali Karbassi --- tests/t1310-listcon.sh | 41 +++++++++++++++++++++++++++++++++++++++++ tests/t1320-listproj.sh | 27 +++++++++++++++++++++++++++ todo.sh | 14 +++++++++++++- 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/tests/t1310-listcon.sh b/tests/t1310-listcon.sh index 9e44def..4294508 100755 --- a/tests/t1310-listcon.sh +++ b/tests/t1310-listcon.sh @@ -65,6 +65,47 @@ test_todo_session 'listcon with project' < todo.txt <>> todo.sh listcon +@GinaTrapani +@home) +@x +@y +EOF +test_todo_session 'listcon limiting to multi-character sequences' <>> TODOTXT_SIGIL_VALID_PATTERN='.\{2,\}' todo.sh listcon +@GinaTrapani +@home) +EOF +test_todo_session 'listcon allowing w: marker before contexts' <>> TODOTXT_SIGIL_BEFORE_PATTERN='\(w:\)\{0,1\}' todo.sh listcon +@GinaTrapani +@OtherContributors +@home) +@x +@y +EOF +test_todo_session 'listcon allowing parentheses around contexts' <>> TODOTXT_SIGIL_BEFORE_PATTERN='(\{0,1\}' TODOTXT_SIGIL_AFTER_PATTERN=')\{0,1\}' todo.sh listcon +@GinaTrapani +@home +@school +@x +@y +EOF +test_todo_session 'listcon with all customizations combined' <>> TODOTXT_SIGIL_VALID_PATTERN='.\{2,\}' TODOTXT_SIGIL_BEFORE_PATTERN='\(w:\)\{0,1\}\((\)\{0,1\}' TODOTXT_SIGIL_AFTER_PATTERN=')\{0,1\}' todo.sh listcon +@GinaTrapani +@OtherContributors +@home +@school +EOF + cat > todo.txt < todo.txt <>> todo.sh listproj ++1 ++sunflowers +EOF +test_todo_session 'listproj limiting to alphabetic characters' <>> TODOTXT_SIGIL_VALID_PATTERN='[a-zA-Z]\{1,\}' todo.sh listproj ++sunflowers +EOF +test_todo_session 'listproj allowing brackets around projects' <>> TODOTXT_SIGIL_BEFORE_PATTERN='\[\{0,1\}' TODOTXT_SIGIL_AFTER_PATTERN='\]\{0,1\}' todo.sh listproj ++1 ++gardening ++landscape ++sunflowers +EOF + +cat > todo.txt < "$TEST_TODO_CUSTOM" cat >> "$TEST_TODO_CUSTOM" <<'EOF' diff --git a/todo.sh b/todo.sh index 39a6ee3..671ee48 100755 --- a/todo.sh +++ b/todo.sh @@ -149,6 +149,9 @@ help() TODOTXT_SORT_COMMAND="sort ..." customize list output TODOTXT_FINAL_FILTER="sed ..." customize list after color, P@+ hiding TODOTXT_SOURCEVAR=\$DONE_FILE use another source for listcon, listproj + TODOTXT_SIGIL_BEFORE_PATTERN="" optionally allow chars preceding +p / @c + TODOTXT_SIGIL_VALID_PATTERN=.* tweak the allowed chars for +p and @c + TODOTXT_SIGIL_AFTER_PATTERN="" optionally allow chars after +p / @c EndVerboseHelp @@ -620,6 +623,9 @@ TODOTXT_SORT_COMMAND=${TODOTXT_SORT_COMMAND:-env LC_COLLATE=C sort -f -k2} TODOTXT_DISABLE_FILTER=${TODOTXT_DISABLE_FILTER:-} TODOTXT_FINAL_FILTER=${TODOTXT_FINAL_FILTER:-cat} TODOTXT_GLOBAL_CFG_FILE=${TODOTXT_GLOBAL_CFG_FILE:-/etc/todo/config} +TODOTXT_SIGIL_BEFORE_PATTERN=${TODOTXT_SIGIL_BEFORE_PATTERN:-} # Allow any other non-whitespace entity before +project and @context; should be an optional match; example: \(w:\)\{0,1\} to allow w:@context. +TODOTXT_SIGIL_VALID_PATTERN=${TODOTXT_SIGIL_VALID_PATTERN:-.*} # Limit the valid characters (from the default any non-whitespace sequence) for +project and @context; example: [a-zA-Z]\{3,\} to only allow alphabetic ones that are at least three characters long. +TODOTXT_SIGIL_AFTER_PATTERN=${TODOTXT_SIGIL_AFTER_PATTERN:-} # Allow any other non-whitespace entity after +project and @context; should be an optional match; example: )\{0,1\} to allow (with the corresponding TODOTXT_SIGIL_BEFORE_PATTERN) enclosing in parentheses. # Export all TODOTXT_* variables export "${!TODOTXT_@}" @@ -1037,7 +1043,13 @@ listWordsWithSigil() FILE=$TODO_FILE [ "$TODOTXT_SOURCEVAR" ] && eval "FILE=$TODOTXT_SOURCEVAR" - eval "$(filtercommand 'cat "${FILE[@]}"' '' "$@")" | grep -o "[^ ]*${sigil}[^ ]\\+" | grep "^$sigil" | sort -u + eval "$(filtercommand 'cat "${FILE[@]}"' '' "$@")" \ + | grep -o "[^ ]*${sigil}[^ ]\\+" \ + | sed -n \ + -e "s#^${TODOTXT_SIGIL_BEFORE_PATTERN//#/\\#}##" \ + -e "s#${TODOTXT_SIGIL_AFTER_PATTERN//#/\\#}\$##" \ + -e "/^${sigil}${TODOTXT_SIGIL_VALID_PATTERN//\//\\/}$/p" \ + | sort -u } export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list listWordsWithSigil getPadding _format die From ddc560c6b950e40d87a06f6034c4972e5ccfab6e Mon Sep 17 00:00:00 2001 From: Luilver Date: Mon, 25 May 2020 10:41:09 -0500 Subject: [PATCH 14/38] Fix #306 (#307) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15c6fed..a41d997 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ > A simple and extensible shell script for managing your todo.txt file. ![CI](https://github.com/todotxt/todo.txt-cli/workflows/CI/badge.svg) -[![GitHub issues](https://img.shields.io/github/issues/todotxt/todo.txt-cli.svg)](https://github.com/todotxt/todo.txt-cli/issues) +[![GitHub issues](https://img.shields.io/github/issues/todotxt/todo.txt-cli.svg)](https://github.com/todotxt/todo.txt-cli/issues) [![GitHub forks](https://img.shields.io/github/forks/todotxt/todo.txt-cli.svg)](https://github.com/todotxt/todo.txt-cli/network) [![GitHub stars](https://img.shields.io/github/stars/todotxt/todo.txt-cli.svg)](https://github.com/todotxt/todo.txt-cli/stargazers) [![GitHub license](https://img.shields.io/github/license/todotxt/todo.txt-cli.svg)](https://raw.githubusercontent.com/todotxt/todo.txt-cli/master/LICENSE) @@ -11,7 +11,7 @@ ![gif](./.github/example.gif) -*Read our [contributing guide](CONTRIBUTING.md) if you're looking to contribute (issues/PRs/etc).* +*Read our [contributing guide][CONTRIBUTING] if you're looking to contribute (issues/PRs/etc).* ## Installation From da45b0f6378388761c6956c21a205bc54f497180 Mon Sep 17 00:00:00 2001 From: Jonas Stehli Date: Wed, 10 Jun 2020 00:05:06 +0200 Subject: [PATCH 15/38] Change Arch Linux AUR link (#310) there is a second version that is much more popular, why not link that one? --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a41d997..04f7bf0 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ make install CONFIG_DIR=/etc INSTALL_DIR=/usr/bin BASH_COMPLETION=/usr/share/bas #### Arch Linux (AUR) -https://aur.archlinux.org/packages/todotxt-git/ +https://aur.archlinux.org/packages/todotxt/ ## Usage From ce38bea819843756f8fc8a4db8ad83fe449afdee Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Tue, 11 Aug 2020 23:03:05 -0500 Subject: [PATCH 16/38] Add note in README to copy config file (#316) Fixes #252 (by adding a note to README) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 04f7bf0..e67d4dc 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,11 @@ Download the latest stable [release][release] for use on your desktop or server. ```shell brew install todo-txt +cp -n /usr/local/opt/todo-txt/todo.cfg ~/.todo.cfg ``` +**Note**: The `-n` flag for `cp` makes sure you do not overwrite an existing file. + ### Linux #### From command line From 7f3ad0d361c26f3452a4df966d83c3e419673058 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Tue, 11 Aug 2020 23:36:24 -0500 Subject: [PATCH 17/38] Update changelog. Tag v2.12.0 --- CHANGELOG.md | 181 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 141 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f997ac5..dde4cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) @@ -6,27 +7,53 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] -## [2.11.0] - 2018-03-26 +## [2.12.0] - 2020-08-11 + ### Added + +- Added default priority variable `TODOTXT_PRIORITY_ON_ADD` ([#246]) +- Added `done` option as alias of `do` ([#169]) +- Added macOS 10.15.x support ([#300]) +- Highlighting of dates, metadata and item numbers ([#264]) +- Minimal config file / default filenames (todo.txt, done.txt, report.txt) ([#289]) +- Enable file completion for add-on actions via `_todo_file{1,2,3}_actions` ([#270]) +- Allow to customize what can be before / inside / after `+project` and `@context` ([#271]) + +### Changed + +- Read the task's name and uses as default ([#249]) +- Updated interpreter reference to use environment variable ([#160]) +- Allow setting of bash completion path ([#301]) + +### Fixes + +- Fixed no end-of-line bug. Supports todos with no end-of-line. ([#295]) + +## [2.11.0] - 2018-03-26 + +### Added + - Added support for `$XDG_CONFIG_HOME` config file/actions location - Created [CODE_OF_CONDUCT.md](.github/CODE_OF_CONDUCT.md) ([#217]) - Created [CHANGELOG.md](/CHANGELOG.md) ([#218]) - ### Changed + - Updated `add` command to accept lowercase priority ([#230]) - Clean tests and version file in Makefile. Don't ignore errors in tests. - Updated [README.md](/README.md) ([#219]) - Update Downloads links to point at the Releases page ([#228]) - Set the executable bit when preparing releases ([#156]) -### Fixes +### Fixes + - Update links to use https - Suppress todo.sh error messages when invoked during completion ([#8]) - ## [2.10.0] - 2013-12-06 + ### Added + - Enable term filtering for listcon. - Add make install command. - Enable use of global config file in `/etc/todo/config`. `make install` installs a global config file. @@ -39,37 +66,45 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Place add-ons in subfolders (for easier git clone). ### Changed + - Improve code commenting/documentation. - Refactor code for speed/better organization. - Improve test coverage and test library. ### Removed + - Removed add date from line completion, ie, `todo.sh ls 10[tab]`. ### Fixed + - Properly replace date when replacing task with priority and date. - Handle `-h`, `shorthelp`, and `help` when a Fatal Error happens. - Fix `todo_completion` problem with Bash 3.1. ## [2.9.0] - 2012-04-08 + ### Added + - Added tab auto-completion of projects and contexts from `todo.txt` and `done.txt`. Type `@` or `+` while entering a task. - Added new listaddons command displays installed addons. - List priorities within a range using listpri. For example, to see tasks prioritized A-B, use `todo.sh listpri A-B` ### Fixed + - Fixed various cosmetic issues, bugs, and added developer test library enhancements. - ## [2.8.0] - 2011-09-13 + ### Added + - `listpri`/`lsp` now filters by term. For example, `todo.sh lsp A book` will only return tasks prioritized `A` with the word book in them. - Added support for todo directory paths with spaces in them. -- Tasks with priority included and auto prepend date on (`-t`) get the date where expected. +- Tasks with priority included and auto prepend date on (`-t`) get the date where expected. - Smarter action completion messaging: `do`, `pri`, and `depri` all let you know if a task is already done, prioritized, or deprioritized. - Made more parameters available to offer more control to custom actions (`-c`, `-A`, `-N`, `-T`) ### Changed + - Improved portability for Dropbox or USB key users. If not specified, todo.sh checks for a config file in its own directory; default todo.txt location is todo.sh's directory. - Improved script performance thanks to optimized code - Exposed `cleaninput()` for use in addons @@ -80,6 +115,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Cleaner, simpler, modernized, optimized code ### Fixed + - Custom action output no longer prefaced by `TODO:` so it's easier to see when the core script vs. addon is performing an action - `listpri` complains if specified priority is invalid - Don't abort task listing when items contain certain escape sequences (`\c \033`) @@ -87,24 +123,29 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Don't delete `|` (pipe) from task input - `-+` and `-@` no longer break task coloring if context or project appears at the end of the line - ## [2.7.0] - 2010-08-03 + ### Added + - Added generalization of the _PRI_X_ color support to all priorities -- Added highlighting of done, but not yet archived tasks via *COLOR_DONE* +- Added highlighting of done, but not yet archived tasks via _COLOR_DONE_ - Color map (BLACK, ...) now supports spaces in the color definitions, making it possible to override the default ANSI escape codes with e.g. Conky tags (`${color black}`) ### Changed + - Cleanup: help messages, consistent output messages - Exporting `die()` function for use in custom commands - `prepend` and `replace` actions keep prepended date, `append` considers sentence delimiters - Tests: several regression tests added ## [2.6.0] - 2010-05-11 + ### Added + - Added a case for the fixed replace command. ### Changed + - Changed odd tabs to spaces. - Faster help/useage document outputs. - Consolidated `TODOTXT_VERBOSE` tests. @@ -112,6 +153,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Updated `_list()` output to match updated `addto`. ### Fixed + - Quoting regexp to parse properly. - Fixed erroneous hide/show comments. - Correctly fixed regexp quoting issue for bash v3.1.x and v3.2.x. @@ -120,7 +162,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed bug for replace command. ## [2.5.0] - 2010-05-05 + ### Added + - Support use of `$HOME/.todo/` for all todo.sh configuration - Added new multiple do capability to help message - Added option to disable final filter @@ -130,42 +174,49 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added some additional mappings, plus a project context ### Changed + - Added 'silent' to a bunch of calls ### Fixed + - Fixing prepend and priority issue. - Replace with `priority` set - Multiple `do` items - `prepend` not correct on prioritized tasks -- Invalid date range. Changed regex `[ -~]` to `[ ~-]`. +- Invalid date range. Changed regex `[ -~]` to `[ ~-]`. - `do`: no safeguard to `do` twice. Tests item is not marked done before attempting to mark item as "done". - Fixed `add` does not escape line breaks - `append` and `replace` unexpected behavior if there's an `&` in task (even in quotes) - Tasks whose `ID` begins with `0` ought to be ignored. - Fixed auto-complete function name for contexts - ## [2.4.0] - 2009-05-11 + ### Added + - Added support for `TODOTXT_FINAL_FILTER` to provide a final custom list filter. - Added support for custom sorting (can set in `todo.cfg`) - Added parameterize for `.todo.actions.d` directory ### Removed + - Removed annoying trailing space on `pri` tasks - Don't set colors in default `todo.cfg`. - Don't set sort command in default `todo.cfg`. ### Fixed + - `listcon` and `listproj` now work correctly on Mac OS X 10.5 - `pri` accepted priorities of more than a single letter -- Support commands combination for `TODOTXT_SORT_COMMAND`; e.g. piped commands can be used: `export TODOTXT_SORT_COMMAND=" env LC_COLLATE=C sort -f -k2 - | grep -m 10 ."` +- Support commands combination for `TODOTXT_SORT_COMMAND`; e.g. piped commands can be used: `export TODOTXT_SORT_COMMAND=" env LC_COLLATE=C sort -f -k2 - | grep -m 10 ."` - Replace now echoes old item AND new item, like it used to. - `depri` no longer wipes out tasks with more than just the priority in parentheses - Now throws an error if you try to prioritize with more than one letter, ie, `todo.sh pri AA` doesn't work any more. ## [2.3.0] - 2009-04-02 + ### Added + - Added hide priority, context, and projects options now enabled `-P`, `-@` and `-+` - Enabled recursive call of todo.sh from add-ons - Exported variables for use in add-ons @@ -174,34 +225,40 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added Makefile dist infrastructure for versioned releases in Downloads area on GitHub ### Changed + - Separated `_list` function for reuse by various versions of list command to reduce duplicate code - Set `ls` as the default action - ## [2.2.0] - 2009-03-?? + ### Fixed + - For awhile here during the GitHub transition, we stripped the version number from todo.sh and updated it kind of willy-nilly, so we're back-versioning all unversioned copies v 2.2. - ## [2.1.0] - 2009-02-23 + ### Added + - Added "pluggability" with `~/.todo.actions.d/` support (via [Tammy and Ed](http://tech.groups.yahoo.com/group/todotxt/message/1739)) - Added `-t` param, off by default. When specified, it automatically prepends the current date to new todo's on add - Searches for more Unix-y `~/.todo.cfg` if `~/todo.cfg` doesn't exist (via [Ed](http://tech.groups.yahoo.com/group/todotxt/message/1767)) ### Fixed + - Corrected "ambiguous redirect" bug with done file (via [Jeff](http://tech.groups.yahoo.com/group/todotxt/message/1764)) - Corrected usage and help message with new params - Corrected config file miscomment about colors - ## [2.0.1] - 2009-02-17 + ### Fixed + - Restored `-d` parameter functionality broken in 2.0 (d'oh, thanks Jason, you made the changelog! ) - ## [2.0.0] - 2009-02-17 + ### Added + - Added `addto [DEST] "Text to add"` will append text to any file in the todo directory, like `ideas.txt` or `maybelater.txt`. - Added `mv # [DEST]` will move a task from `todo.txt` to another file `[DEST]` in the todo directory, like if you decide your `"Learn French"` task should go into your `maybelater.txt` file. - `depri #` removes priority from a task. @@ -212,76 +269,92 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Auto-archive on task completion is now on by default; can be turned off with `-a` parameter. ### Changed + - Separated config file into a non hidden dot file. ### Fixed + - Better error handling throughout for all commands. - Archive now defrags the file (removes blank lines; see line preservation option.) - Using `/bin/bash` instead of `/bin/sh` - ## [1.7.3] - 2006-07-29 + ### Added + - Added short action aliases – `add/a`, `list/ls`, `listpri/lsp`, `listall/lsa`, `prepend/prep`, `append/app`, `del/rm` - ## [1.7.2] - 2006-07-28 + ### Added + - `listpri` automatically capitalizes lowercase priorities - `listpri` now displays friendly error message, and the # of tasks returned in verbose mode ### Changed + - `do` action removes priority from task automatically Update: ### Fixed + - Actions are now case-insensitive (ie, `todo.sh Add` will work) - ## [1.7.1] - 2006-07-21 + ### Changed + - I'm a big dummy and didn't keep track of what I fixed here. Sorry! - ## [1.7.0] - 2006-07-19 + ### Added + - Interactive `add`, `append`, `prepend`, and `replace` (tx, Ben!) - Action `listall` displays tasks from both todo.txt and done.txt - Option `-f` forces delete action and disables interactive input (for todobot.pl) - Option `-h` displays full help message. ### Deprecated + - Option `-q` deprecated; Use `-v` to turn on verbose mode ### Changed + - A very short version of usage message displays by default instead of the long version. - Comment in info about `.todo` file being required ### Fixed + - No colors display for done tasks (tx, Tanja!) - Sort is now case-insensitive (tx, Lonnie!) - ## [1.6.3] - 2006-07-06 + ### Added + - Line numbers now padded, up to 100 characters. (tx, Tanja!) - ## [1.6.2] - 2006-07-05 + ### Fixed + - Windows config files with spaces now work (tx Ron) - ## [1.6.1] - 2006-07-05 + ### Changed + - The default location of your `.todo` file is now `$HOME/.todo` ### Fixed + - No colors mode (`-p`) now works as expected - ## [1.6.0] - 2006-07-04 + ### Added + - Action `prepend` adds text to an item at the beginning of the line. - Configuration file is now separated from script into `.todo` file - Specify a config file other than `.todo` using the `-d` option @@ -289,89 +362,107 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Option `-V` shows version and license information. ### Changed + - The option to turn off colors is now `-p` (no longer `-nc` as in 1.5.2) - ## [1.5.2] - 2006-06-26 + ### Fixed + - Items that start with `x ` (an x with a space after) are archived now to avoid lines that start with a word like `xander` from being archived. (tx, Tannie!) - Report now only archives items that start with `x ` as well. - ## [1.5.1] - 2006-06-26 + ### Fixed + - Items with an `x` in them at all were being deleted on archive with 1.5; all fixed now. - ## [1.5.0] - 2006-06-24 + ### Added + - Option to turn off colors (to avoid characters in piped text files or IM bot), ie `todo.sh -nc [COMMAND]` - A date is added to a completed todo, ie `x 2006-06-24` (tx SETH) - Action `remdup` removes exact duplicate lines from todo.txt (tx Tannie) - Action `del` removes any blank lines from todo.txt (tx Tannie) ### Changed + - Using `sed -i` instead of copying tmp file (tx Tannie) ### Fixed + - Colors show in OS/X 10.4 (tx SETH & misha) - ## [1.4.0] - 2006-06-17 + ### Added + - Tasks are color-coded by priority in Cygwin (Thanks, Abraham, Manuel and Luis!) ### Changed + - Switched endless `if-then` to a `case` statement, and tightened up `wc -l` regex. (Thanks, Sash!) ### Fixed + - If you `replace`/`do`/`append` to a non-existent task, your todo.txt is no longer overwritten and the error is handled gracefully. (Thanks, Scott!) - ## [1.3.0] - 2006-05-29 + ### Added + - Displays the number of newly added todo (Thanks, Amy!) - Confirms whether or not you really want to delete a todo - Displays success messages and confirmations on `append`, `replace`, `do`, etc. - Added licensing information in comments. GPL, baby! ### Changed + - Alphabetized command workflow in if/then construction - Tightened up `sed` commands, removed unnecessary `grep`s and `cat`s (Thanks, Sash!) - Stripped whitespace around number lines from wc results ### Removed + - Removed filenames from `report.txt` format, for easier graphing or Excel imports. ### Fixed + - Todos are now sorted alphabetically when listed by a term. (ie: `todo list flowers) - ## [1.2.0] - 2006-05-15 + ### Added + - `list` is case insenstive. ie, `todo list Mac` will match lines with "mac" and "Mac" ### Changed + - `todo list` matches multiple [TERM]s. ie, `todo list mac offline` will match all lines that contain the words "mac" and "offline" - `repri` and `pri` actions combined into `pri` action (Thanks Mike!) - Quotes no longer required with `add` and `replace` (Thanks Karl!) - Any priority added to a todo must be uppercase to preserve sort order, enforced now. ie `todo pri 1 a` will return a usage error. ### Fixed + - File "sanity checks" and cleanup function, test script and various fantastic stylistic improvements added. Extra big thanks to Karl! - ## [1.1.0] - 2006-05-12 + ### Added + - Supports file paths with spaces (ie `C:\Documents and Settings\gina\todo.txt`) - ## 1.0.0 - 2006-05-11 + ### Added + - Consolidated into one master script with usage notes and released. - -[Unreleased]: https://github.com/todotxt/todo.txt-cli/compare/v2.11.0...HEAD +[Unreleased]: https://github.com/todotxt/todo.txt-cli/compare/v2.12.0...HEAD +[2.12.0]: https://github.com/todotxt/todo.txt-cli/compare/v2.11.0...v2.12.0 [2.11.0]: https://github.com/todotxt/todo.txt-cli/compare/v2.10.0...v2.11.0 [2.10.0]: https://github.com/todotxt/todo.txt-cli/compare/v2.9.0...v2.10.0 [2.9.0]: https://github.com/todotxt/todo.txt-cli/compare/v2.8.0...v2.9.0 @@ -400,11 +491,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [1.3.0]: https://github.com/todotxt/todo.txt-cli/compare/v1.2.0...v1.3.0 [1.2.0]: https://github.com/todotxt/todo.txt-cli/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.com/todotxt/todo.txt-cli/compare/v1.0.0...v1.1.0 - -[#230]: https://github.com/todotxt/todo.txt-cli/pull/230 -[#228]: https://github.com/todotxt/todo.txt-cli/pull/228 -[#219]: https://github.com/todotxt/todo.txt-cli/pull/219 -[#218]: https://github.com/todotxt/todo.txt-cli/pull/218 -[#217]: https://github.com/todotxt/todo.txt-cli/pull/217 -[#156]: https://github.com/todotxt/todo.txt-cli/pull/156 [#8]: https://github.com/todotxt/todo.txt-cli/pull/8 +[#156]: https://github.com/todotxt/todo.txt-cli/pull/156 +[#160]: https://github.com/todotxt/todo.txt-cli/pull/160 +[#169]: https://github.com/todotxt/todo.txt-cli/pull/169 +[#217]: https://github.com/todotxt/todo.txt-cli/pull/217 +[#218]: https://github.com/todotxt/todo.txt-cli/pull/218 +[#219]: https://github.com/todotxt/todo.txt-cli/pull/219 +[#228]: https://github.com/todotxt/todo.txt-cli/pull/228 +[#230]: https://github.com/todotxt/todo.txt-cli/pull/230 +[#246]: https://github.com/todotxt/todo.txt-cli/pull/246 +[#249]: https://github.com/todotxt/todo.txt-cli/pull/249 +[#264]: https://github.com/todotxt/todo.txt-cli/pull/264 +[#270]: https://github.com/todotxt/todo.txt-cli/pull/270 +[#271]: https://github.com/todotxt/todo.txt-cli/pull/271 +[#289]: https://github.com/todotxt/todo.txt-cli/pull/289 +[#295]: https://github.com/todotxt/todo.txt-cli/pull/295 +[#300]: https://github.com/todotxt/todo.txt-cli/pull/300 +[#301]: https://github.com/todotxt/todo.txt-cli/pull/301 From ae1f24188721bae2052123651ff2c0a138df9717 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Thu, 10 Sep 2020 13:12:04 -0500 Subject: [PATCH 18/38] Update zip file creation to use native zip command. (#319) Fixes #318 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0bdcf74..58c1e69 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ dist: $(DISTFILES) todo.sh chmod +x $(DISTNAME)/todo.sh tar cf $(DISTNAME).tar $(DISTNAME) gzip -f -9 $(DISTNAME).tar - tar cf $(DISTNAME).zip $(DISTNAME) + zip -r -9 $(DISTNAME).zip $(DISTNAME) rm -r $(DISTNAME) .PHONY: clean From 7bac9d861bfaa3f98a2f30fde6734cf1a89ec69e Mon Sep 17 00:00:00 2001 From: Oleg Zaytsev Date: Thu, 22 Oct 2020 07:36:05 +0200 Subject: [PATCH 19/38] s/GREY/GRAY/ in todo.cfg (#320) `GRAY` is the spelling used in every other place in this repository. --- todo.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.cfg b/todo.cfg index 886a533..4d6adc8 100644 --- a/todo.cfg +++ b/todo.cfg @@ -67,7 +67,7 @@ export REPORT_FILE="$TODO_DIR/report.txt" # export COLOR_PROJECT=$RED # export COLOR_CONTEXT=$RED # export COLOR_DATE=$BLUE -# export COLOR_NUMBER=$LIGHT_GRAY +# export COLOR_NUMBER=$LIGHT_GREY # There is highlighting for metadata key:value pairs e.g. # DUE:2006-08-01 or note:MYNOTE From 797604e2b606ffeb7625c8ab792aeb8b6b6e700e Mon Sep 17 00:00:00 2001 From: Daniel M Date: Fri, 20 Nov 2020 21:33:06 -0500 Subject: [PATCH 20/38] Fixed tests on ubuntu #317 (#322) Tests failed on Ubuntu due to regular expression - corrected regex and now it works. --- todo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.sh b/todo.sh index 671ee48..1de99af 100755 --- a/todo.sh +++ b/todo.sh @@ -1007,7 +1007,7 @@ _format() printf "%s", prj_beg words[i] prj_end } else if (words[i] ~ /^[@].*[A-Za-z0-9_]$/) { printf "%s", ctx_beg words[i] ctx_end - } else if (words[i] ~ /^(19|20)[0-9]{2}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/) { + } else if (words[i] ~ /^(19|20)[0-9][0-9]-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/) { printf "%s", dat_beg words[i] dat_end } else if (words[i] ~ /^[[:alnum:]]+:[^ ]+$/) { printf "%s", met_beg words[i] met_end From 6188785e488debe722ac1f4bb6c70ec7fb12d575 Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Fri, 4 Dec 2020 13:32:53 -0800 Subject: [PATCH 21/38] Fix tests on Debian (#326) Corrected an additional regex to match tags on mawk 1.3.3 in Debian --- todo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.sh b/todo.sh index 1de99af..c7d8564 100755 --- a/todo.sh +++ b/todo.sh @@ -1009,7 +1009,7 @@ _format() printf "%s", ctx_beg words[i] ctx_end } else if (words[i] ~ /^(19|20)[0-9][0-9]-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/) { printf "%s", dat_beg words[i] dat_end - } else if (words[i] ~ /^[[:alnum:]]+:[^ ]+$/) { + } else if (words[i] ~ /^[A-Za-z0-9]+:[^ ]+$/) { printf "%s", met_beg words[i] met_end } else { printf "%s", words[i] From 71b3991daf1d9686c3d548b18a6f2b0b9e1b3ea0 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Fri, 11 Dec 2020 13:07:11 -0600 Subject: [PATCH 22/38] Gitter chat to Github Discussions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e67d4dc..af1fc36 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,8 @@ See [CHANGELOG.md][CHANGELOG] ## Support +- [Github Discussions](https://github.com/todotxt/todo.txt-cli/discussions) - [Stack Overflow](https://stackoverflow.com/questions/tagged/todotxt) -- [Gitter chat](https://gitter.im/todotxt/todo.txt-cli) - [Twitter](https://twitter.com/todotxt) From 77c1f34609070135143f29395edc647a2d308311 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sat, 13 Mar 2021 20:32:40 +0100 Subject: [PATCH 23/38] Documentation: Clarify basic regexp syntax of TERM in todo.sh list (#335) * Documentation: Clarify basic regexp syntax of TERM in todo.sh list And give hints about escaping. Issue raised by https://github.com/todotxt/todo.txt-cli/discussions/334 * Documentation: Correct quoting in todo.sh help list Though the double quoting doesn't do harm when the single backslash is followed by the | character (\| is no valid escape sequence), it's technically more correct to use single quotes, and also is more in line with the quoting advice given directly below it. --- todo.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/todo.sh b/todo.sh index c7d8564..11687d2 100755 --- a/todo.sh +++ b/todo.sh @@ -217,9 +217,13 @@ actionsHelp() Displays all tasks that contain TERM(s) sorted by priority with line numbers. Each task must match all TERM(s) (logical AND); to display tasks that contain any TERM (logical OR), use - "TERM1\|TERM2\|..." (with quotes), or TERM1\\\|TERM2 (unquoted). + 'TERM1\|TERM2\|...' (with quotes), or TERM1\\\|TERM2 (unquoted). Hides all tasks that contain TERM(s) preceded by a - minus sign (i.e. -TERM). If no TERM specified, lists entire todo.txt. + minus sign (i.e. -TERM). + TERM(s) are grep-style basic regular expressions; for literal matching, + put a single backslash before any [ ] \ $ * . ^ and enclose the entire + TERM in single quotes, or use double backslashes and extra shell-quoting. + If no TERM specified, lists entire todo.txt. listall [TERM...] lsa [TERM...] From e4103a8e231d89cb42eb1691374b701988d2a368 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Tue, 3 Aug 2021 17:53:35 -0500 Subject: [PATCH 24/38] Add Ubuntu 18 to tests (#351) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b6232ee..eeea980 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: test: strategy: matrix: - platform: [ubuntu-latest, macos-latest] + platform: [ubuntu-latest, macos-latest, ubuntu-18.04] runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 From f884f73297a87f3a89202d5cedc7ea7d6e7096d4 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 4 Aug 2021 00:57:31 +0200 Subject: [PATCH 25/38] TESTSFIX: t0000-config.sh may unintentionally pick up existing user config in $XDG_CONFIG_HOME/todo/config (#349) * TESTSFIX: t0000-config.sh may unintentionally pick up existing user config in `$XDG_CONFIG_HOME/todo/config` This corner case was missed when the XDG alternative config location was introduced, likely because the variable isn't set by default on Ubuntu or Mac OS, and none of the developers had a config there. HOME is already redirected to the current working directory; as `XDG_CONFIG_HOME` is just a config alternative that has a fallback to `$HOME/.config`, simply unset it. Fixes #347 * TESTSFIX: User add-ons that override built-in actions may break tests If `TODO_ACTIONS_DIR` is already defined, the defaulting in todo.sh are skipped. The user may have custom add-ons that override built-in actions; any incompatible behavior would negatively affect the tests then. By setting the variable to the first default location, we avoid this interference. --- tests/test-lib.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 18655bc..499f9c7 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -693,6 +693,13 @@ cd -P "$test" || exit 1 # but use something specified by the framework. HOME=$(pwd) export HOME +# Unset XDG_CONFIG_HOME as that is used as a config alternative. +unset XDG_CONFIG_HOME +# User add-ons may override built-in commands; these could have incompatible +# behavior that makes the tests fail. Avoid picking up user add-ons by +# explicitly configuring the first default location (which with the redirected +# HOME lies within the test directory and usually does not exist). +export TODO_ACTIONS_DIR="$HOME/.todo/actions" this_test=${0##*/} this_test=${this_test%%-*} From 353db498141544acce1566ff316bcfc1957093eb Mon Sep 17 00:00:00 2001 From: Paul Mansfield Date: Wed, 4 Aug 2021 00:03:20 +0100 Subject: [PATCH 26/38] Allow multiple priorities on single run (#346) Uses current priority logic and option tests just running multiple times until item and priority pairs are exhausted or stops on first error. Tests for multiple priorities, multiple re-prioritization and a couple of errors. --- tests/t1200-pri.sh | 37 ++++++++++++++++++++++++++++++- todo.sh | 54 +++++++++++++++++++++++++--------------------- 2 files changed, 65 insertions(+), 26 deletions(-) diff --git a/tests/t1200-pri.sh b/tests/t1200-pri.sh index 62b479c..fd8bd10 100755 --- a/tests/t1200-pri.sh +++ b/tests/t1200-pri.sh @@ -6,7 +6,7 @@ test_description='basic priority functionality test_todo_session 'priority usage' <>> todo.sh pri B B -usage: todo.sh pri ITEM# PRIORITY +usage: todo.sh pri ITEM# PRIORITY[, ITEM# PRIORITY, ...] note: PRIORITY must be anywhere from A to Z. === 1 EOF @@ -100,4 +100,39 @@ TODO: 2 already prioritized (A). -- TODO: 3 of 3 tasks shown EOF + +cat > todo.txt <>> todo.sh pri 1 A 2 B +1 (A) smell the uppercase Roses +flowers @outside +TODO: 1 prioritized (A). +2 (B) notice the sunflowers +TODO: 2 prioritized (B). +EOF + +test_todo_session 'multiple reprioritize' <>> todo.sh pri 1 Z 2 X +1 (Z) smell the uppercase Roses +flowers @outside +TODO: 1 re-prioritized from (A) to (Z). +2 (X) notice the sunflowers +TODO: 2 re-prioritized from (B) to (X). +EOF + +test_todo_session 'multiple prioritize error' <>> todo.sh pri 1 B 4 B +=== 1 +1 (B) smell the uppercase Roses +flowers @outside +TODO: 1 re-prioritized from (Z) to (B). +TODO: No task 4. + +>>> todo.sh pri 1 C 4 B 3 A +=== 1 +1 (C) smell the uppercase Roses +flowers @outside +TODO: 1 re-prioritized from (B) to (C). +TODO: No task 4. +EOF test_done diff --git a/todo.sh b/todo.sh index 11687d2..6c35944 100755 --- a/todo.sh +++ b/todo.sh @@ -62,7 +62,7 @@ shorthelp() listproj|lsprj [TERM...] move|mv ITEM# DEST [SRC] prepend|prep ITEM# "TEXT TO PREPEND" - pri|p ITEM# PRIORITY + pri|p ITEM# PRIORITY[, ITEM# PRIORITY, ...] replace ITEM# "UPDATED TODO" report shorthelp @@ -1405,38 +1405,42 @@ case $action in ;; "pri" | "p" ) - item=$2 - newpri=$( printf "%s\n" "$3" | tr '[:lower:]' '[:upper:]' ) + shift + while [ "$#" -gt 0 ] ; do + item=$1 + newpri=$( printf "%s\n" "$2" | tr '[:lower:]' '[:upper:]' ) - errmsg="usage: $TODO_SH pri ITEM# PRIORITY + errmsg="usage: $TODO_SH pri ITEM# PRIORITY[, ITEM# PRIORITY, ...] note: PRIORITY must be anywhere from A to Z." - [ "$#" -ne 3 ] && die "$errmsg" - [[ "$newpri" = @([A-Z]) ]] || die "$errmsg" - getTodo "$item" + [ "$#" -lt 2 ] && die "$errmsg" + [[ "$newpri" = @([A-Z]) ]] || die "$errmsg" + getTodo "$item" - oldpri= - if [[ "$todo" = \(?\)\ * ]]; then - oldpri=${todo:1:1} - fi + oldpri= + if [[ "$todo" = \(?\)\ * ]]; then + oldpri=${todo:1:1} + fi - if [ "$oldpri" != "$newpri" ]; then - sed -i.bak -e "${item}s/^(.) //" -e "${item}s/^/($newpri) /" "$TODO_FILE" - fi - if [ "$TODOTXT_VERBOSE" -gt 0 ]; then - getNewtodo "$item" - echo "$item $newtodo" if [ "$oldpri" != "$newpri" ]; then - if [ "$oldpri" ]; then - echo "TODO: $item re-prioritized from ($oldpri) to ($newpri)." - else - echo "TODO: $item prioritized ($newpri)." + sed -i.bak -e "${item}s/^(.) //" -e "${item}s/^/($newpri) /" "$TODO_FILE" + fi + if [ "$TODOTXT_VERBOSE" -gt 0 ]; then + getNewtodo "$item" + echo "$item $newtodo" + if [ "$oldpri" != "$newpri" ]; then + if [ "$oldpri" ]; then + echo "TODO: $item re-prioritized from ($oldpri) to ($newpri)." + else + echo "TODO: $item prioritized ($newpri)." + fi fi fi - fi - if [ "$oldpri" = "$newpri" ]; then - echo "TODO: $item already prioritized ($newpri)." - fi + if [ "$oldpri" = "$newpri" ]; then + echo "TODO: $item already prioritized ($newpri)." + fi + shift; shift + done ;; "replace" ) From 6ea2b5ae6d0606006e298ee9ca56217ffaa833d2 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 4 Aug 2021 01:06:10 +0200 Subject: [PATCH 27/38] Mention all (also XDG) config file locations in help for -d (#343) * Refactoring: Replace serial checks for `TODOTXT_CFG_FILE` and `TODO_ACTIONS_DIR` with loops Two fallbacks (like for the actions dir) may still be fine, but we're now supporting so many config locations that a loop is much shorter, and the various locations are much easier to see. For consistency, also apply this to the actions dir lookup, although it's less of a problem there. * Refactoring: Apply the first default for `TODOTXT_CFG_FILE` also in the loop There's no need to handle this separately; either an exported environment variable already exists, or it got assigned via `-d CONFIG_FILE`, or the `test -e` will fail on an empty (or bad non-existing) value, and we enter the fallback loop. * Mention the actual config file locations in the help for `-d` Extract the list of default locations into a `configFileLocations` array and join that into a string that then gets interpolated into the help output for `-d` (that so far only mentioned the first default location). * Comments: Don't favor a single config location in the requirement * Documentation: Mention `~/.todo/config` as just one of the defaults As there are several others, now shown in the help for `-d`. I don't want to duplicate the entire list here, as there's a high risk of those lists diverging. Fixes #342 --- USAGE.md | 2 +- todo.sh | 81 +++++++++++++++++--------------------------------------- 2 files changed, 26 insertions(+), 57 deletions(-) diff --git a/USAGE.md b/USAGE.md index 81d591d..3db9094 100644 --- a/USAGE.md +++ b/USAGE.md @@ -221,7 +221,7 @@ Hide project names in list output. Use twice to show project names (default). Color mode ### `-d CONFIG_FILE` -Use a configuration file other than the default `~/.todo/config` +Use a configuration file other than one of the defaults (e.g. `~/.todo/config`) ### `-f` Forces actions without confirmation or interactive input. diff --git a/todo.sh b/todo.sh index 6c35944..9bf6393 100755 --- a/todo.sh +++ b/todo.sh @@ -3,8 +3,8 @@ # === HEAVY LIFTING === shopt -s extglob extquote -# NOTE: Todo.sh requires the .todo/config configuration file to run. -# Place the .todo/config file in your home directory or use the -d option for a custom location. +# NOTE: Todo.sh requires a configuration file to run. +# Place it in one of the default locations or use the -d option for a custom location. [ -f VERSION-FILE ] && . VERSION-FILE || VERSION="@DEV_VERSION@" version() { @@ -83,6 +83,8 @@ shorthelp() help() { + local indentedJoinedConfigFileLocations + printf -v indentedJoinedConfigFileLocations ' %s\n' "${configFileLocations[@]}" cat <<-EndOptionsHelp Usage: $oneline_usage @@ -96,7 +98,8 @@ help() -c Color mode -d CONFIG_FILE - Use a configuration file other than the default ~/.todo/config + Use a configuration file other than one of the defaults: +$indentedJoinedConfigFileLocations -f Forces actions without confirmation or interactive input -h @@ -616,7 +619,6 @@ shift $((OPTIND - 1)) # defaults if not yet defined TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1} TODOTXT_PLAIN=${TODOTXT_PLAIN:-0} -TODOTXT_CFG_FILE=${TODOTXT_CFG_FILE:-$HOME/.todo/config} TODOTXT_FORCE=${TODOTXT_FORCE:-0} TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1} TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1} @@ -676,50 +678,23 @@ export COLOR_DONE=$LIGHT_GREY # color for done (but not yet archived) tasks # (todo.sh add 42 ", foo") syntactically correct. export SENTENCE_DELIMITERS=',.:;' -[ -e "$TODOTXT_CFG_FILE" ] || { - CFG_FILE_ALT="$HOME/todo.cfg" +configFileLocations=( + "$HOME/.todo/config" + "$HOME/todo.cfg" + "$HOME/.todo.cfg" + "${XDG_CONFIG_HOME:-$HOME/.config}/todo/config" + "$(dirname "$0")/todo.cfg" + "$TODOTXT_GLOBAL_CFG_FILE" +) +[ -e "$TODOTXT_CFG_FILE" ] || for CFG_FILE_ALT in "${configFileLocations[@]}" +do if [ -e "$CFG_FILE_ALT" ] then TODOTXT_CFG_FILE="$CFG_FILE_ALT" + break fi -} - -[ -e "$TODOTXT_CFG_FILE" ] || { - CFG_FILE_ALT="$HOME/.todo.cfg" - - if [ -e "$CFG_FILE_ALT" ] - then - TODOTXT_CFG_FILE="$CFG_FILE_ALT" - fi -} - -[ -e "$TODOTXT_CFG_FILE" ] || { - CFG_FILE_ALT="${XDG_CONFIG_HOME:-$HOME/.config}/todo/config" - - if [ -e "$CFG_FILE_ALT" ] - then - TODOTXT_CFG_FILE="$CFG_FILE_ALT" - fi -} - -[ -e "$TODOTXT_CFG_FILE" ] || { - CFG_FILE_ALT=$(dirname "$0")"/todo.cfg" - - if [ -e "$CFG_FILE_ALT" ] - then - TODOTXT_CFG_FILE="$CFG_FILE_ALT" - fi -} - -[ -e "$TODOTXT_CFG_FILE" ] || { - CFG_FILE_ALT="$TODOTXT_GLOBAL_CFG_FILE" - - if [ -e "$CFG_FILE_ALT" ] - then - TODOTXT_CFG_FILE="$CFG_FILE_ALT" - fi -} +done if [ -z "$TODO_ACTIONS_DIR" ] || [ ! -d "$TODO_ACTIONS_DIR" ] @@ -728,26 +703,20 @@ then export TODO_ACTIONS_DIR fi -[ -d "$TODO_ACTIONS_DIR" ] || { - TODO_ACTIONS_DIR_ALT="$HOME/.todo.actions.d" - +[ -d "$TODO_ACTIONS_DIR" ] || for TODO_ACTIONS_DIR_ALT in \ + "$HOME/.todo.actions.d" \ + "${XDG_CONFIG_HOME:-$HOME/.config}/todo/actions" +do if [ -d "$TODO_ACTIONS_DIR_ALT" ] then TODO_ACTIONS_DIR="$TODO_ACTIONS_DIR_ALT" + break fi -} +done -[ -d "$TODO_ACTIONS_DIR" ] || { - TODO_ACTIONS_DIR_ALT="${XDG_CONFIG_HOME:-$HOME/.config}/todo/actions" - - if [ -d "$TODO_ACTIONS_DIR_ALT" ] - then - TODO_ACTIONS_DIR="$TODO_ACTIONS_DIR_ALT" - fi -} # === SANITY CHECKS (thanks Karl!) === -[ -r "$TODOTXT_CFG_FILE" ] || dieWithHelp "$1" "Fatal Error: Cannot read configuration file $TODOTXT_CFG_FILE" +[ -r "$TODOTXT_CFG_FILE" ] || dieWithHelp "$1" "Fatal Error: Cannot read configuration file ${TODOTXT_CFG_FILE:-${configFileLocations[0]}}" . "$TODOTXT_CFG_FILE" From 7501d37b45c9af4444fb1fee1e403044240937e7 Mon Sep 17 00:00:00 2001 From: Wallysson Date: Tue, 3 Aug 2021 20:10:28 -0300 Subject: [PATCH 28/38] use builtin "command -v" instead of which (#308) --- todo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/todo.sh b/todo.sh index 9bf6393..5348200 100755 --- a/todo.sh +++ b/todo.sh @@ -1252,7 +1252,7 @@ case $action in actionUsage "$@" else if [ -t 1 ] ; then # STDOUT is a TTY - if which "${PAGER:-less}" >/dev/null 2>&1; then + if command -v "${PAGER:-less}" >/dev/null 2>&1; then # we have a working PAGER (or less as a default) help | "${PAGER:-less}" && exit 0 fi @@ -1263,7 +1263,7 @@ case $action in "shorthelp" ) if [ -t 1 ] ; then # STDOUT is a TTY - if which "${PAGER:-less}" >/dev/null 2>&1; then + if command -v "${PAGER:-less}" >/dev/null 2>&1; then # we have a working PAGER (or less as a default) shorthelp | "${PAGER:-less}" && exit 0 fi From eb7feaefb56a44b9773303188bccce98c2e2d1b4 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 3 Aug 2021 16:11:27 -0700 Subject: [PATCH 29/38] Fix problem with spaces in directory path (#276) If the current directory had spaces in the directory path, this script would fail. That has been fixed by appropriate use of quotes. Co-authored-by: Tim Learmont Co-authored-by: Ali Karbassi --- tests/test-lib.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 499f9c7..aef6c96 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -414,12 +414,12 @@ test_done () { mkdir -p "$test_results_dir" test_results_path="$test_results_dir/${0%.sh}-$$" - echo "total $test_count" >> $test_results_path - echo "success $test_success" >> $test_results_path - echo "fixed $test_fixed" >> $test_results_path - echo "broken $test_broken" >> $test_results_path - echo "failed $test_failure" >> $test_results_path - echo "" >> $test_results_path + echo "total $test_count" >> "$test_results_path" + echo "success $test_success" >> "$test_results_path" + echo "fixed $test_fixed" >> "$test_results_path" + echo "broken $test_broken" >> "$test_results_path" + echo "failed $test_failure" >> "$test_results_path" + echo "" >> "$test_results_path" if test "$test_fixed" != 0 then @@ -476,7 +476,7 @@ test_init_todo () { mkdir -p "$root" cd "$root" || error "Cannot setup todo dir in $root" # Initialize the configuration file. Carefully quoted. - sed -e 's|TODO_DIR=.*$|TODO_DIR="'"$TEST_DIRECTORY/$test"'"|' $TEST_DIRECTORY/../todo.cfg > todo.cfg + sed -e 's|TODO_DIR=.*$|TODO_DIR="'"$TEST_DIRECTORY/$test"'"|' "$TEST_DIRECTORY/../todo.cfg" > todo.cfg # Install latest todo.sh mkdir bin From 587833bb4e6855f61385d8fa75c6746069f344ec Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 6 Aug 2021 10:14:25 -0400 Subject: [PATCH 30/38] Default to user writable directory in config (#148) When a user installs from a package manager (MacPorts, Homebrew, `yum`, etc.), the `todo.sh` script is installed into a restricted folder. This means that the result of `$(basename "$0")` is a directory where the user cannot write without elevated permissions. This generates additional noise when the user first runs `todo.sh -h`. An alternative is to default to the user's personal directory which is known to exist and will be writable by the user. --- todo.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.cfg b/todo.cfg index 4d6adc8..0ab7d9b 100644 --- a/todo.cfg +++ b/todo.cfg @@ -2,7 +2,7 @@ # Your todo.txt directory (this should be an absolute path) #export TODO_DIR="/Users/gina/Documents/todo" -export TODO_DIR=$(dirname "$0") +export TODO_DIR=${HOME:-$USERPROFILE} # Your todo/done/report.txt locations export TODO_FILE="$TODO_DIR/todo.txt" From ee94a3fac50c4fc17a1b12ac1e3d865cb1f8f7dd Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 6 Aug 2021 22:05:11 +0200 Subject: [PATCH 31/38] Return from user prompt without requiring Enter (#354) * Tests: Add coverage for del / move without -f, but with prompting Supplying the user confirmation via "yes". * Cosmetics: Align inconsistent spacing for before (y/n) prompt * Refactoring: Extract confirm() function The user confirmation query had been duplicated (once) in the code. * Refactoring: confirm(): Leave early if forced * Return from user prompt without requiring Enter By just reading a single character (y for yes, anything else: no). * Tests: Ensure that only a single "y" concludes the confirmation By switching from "yes" (that endlessly prints newline-separated "y"s) to "printf y". * t1800-del: Add coverage for negative confirmation Negative means "anything but y", so "n", "x", and Enter all apply. * Cosmetics: Add trailing space after (y/n) prompt So that the user's typed answer is not recorded directly after it, but with separation: "Foo? (y/n) y" instead of "Foo? (y/n)y". *Compatibility: "read -N 1" is only available in Bash 4.1+ Mac OS still ships with Bash 3.2 :-( Fall back to the original prompting that requires conclusion via Enter then. Note: Even though the tests use "printf y", this still gets accepted, as there'll be EOF after that. In real use (when stdin from the terminal stays open), a concluding Enter is mandatory, though. Closes #152 --- tests/t1800-del.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++ tests/t1850-move.sh | 29 ++++++++++++++++++++++++++++ todo.sh | 30 +++++++++++++++-------------- 3 files changed, 91 insertions(+), 14 deletions(-) diff --git a/tests/t1800-del.sh b/tests/t1800-del.sh index c9fc744..6d96e89 100755 --- a/tests/t1800-del.sh +++ b/tests/t1800-del.sh @@ -4,6 +4,8 @@ test_description='basic del functionality ' . ./test-lib.sh +SPACE=' ' + test_todo_session 'del usage' <>> todo.sh del B usage: todo.sh del ITEM# [TERM] @@ -44,6 +46,50 @@ TODO: 1 deleted. TODO: 2 of 2 tasks shown EOF +cat > todo.txt <>> todo.sh -p list +2 (A) notice the sunflowers +1 (B) smell the uppercase Roses +flowers @outside +3 stop +-- +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. + +>>> todo.sh -p list +2 (A) notice the sunflowers +1 (B) smell the uppercase Roses +flowers @outside +3 stop +-- +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. + +>>> echo | todo.sh del 1 +Delete '(B) smell the uppercase Roses +flowers @outside'? (y/n)$SPACE +TODO: No tasks were deleted. + +>>> 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. + +>>> todo.sh -p list +2 (A) notice the sunflowers +3 stop +-- +TODO: 2 of 2 tasks shown +EOF + cat > todo.txt < todo.txt < todo.txt < done.txt <>> 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'. + +>>> todo.sh -p ls +2 (A) notice the sunflowers +-- +TODO: 1 of 1 tasks shown + +>>> todo.sh -p listfile done.txt +3 (B) smell the uppercase Roses +flowers @outside +1 x 2009-02-13 make the coffee +wakeup +2 x 2009-02-13 smell the coffee +wakeup +-- +DONE: 3 of 3 tasks shown +EOF + test_todo_session 'basic move with passed source' <>> todo.sh -f move 2 todo.txt done.txt | sed "s#'[^']\{1,\}/\([^/']\{1,\}\)'#'\1'#g" 2 x 2009-02-13 smell the coffee +wakeup diff --git a/todo.sh b/todo.sh index 5348200..2e1dca8 100755 --- a/todo.sh +++ b/todo.sh @@ -362,6 +362,20 @@ die() exit 1 } +confirm() +{ + [ $TODOTXT_FORCE = 0 ] || return 0 + + printf %s "${1:?}? (y/n) " + local readArgs=(-e -r) + [ -n "${BASH_VERSINFO:-}" ] && [ \( ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 \) -o ${BASH_VERSINFO[0]} -gt 4 ] && + readArgs+=(-N 1) # Bash 4.1+ supports -N nchars + local answer + read "${readArgs[@]}" answer + echo + [ "$answer" = "y" ] +} + cleaninput() { # Parameters: When $1 = "for sed", performs additional escaping for use @@ -1146,13 +1160,7 @@ case $action in getTodo "$item" if [ -z "$3" ]; then - if [ $TODOTXT_FORCE = 0 ]; then - echo "Delete '$todo'? (y/n)" - read -e -r ANSWER - else - ANSWER="y" - fi - if [ "$ANSWER" = "y" ]; then + if confirm "Delete '$todo'"; then if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then # delete line (changes line numbers) sed -i.bak -e "${item}s/^.*//" -e '/./!d' "$TODO_FILE" @@ -1342,13 +1350,7 @@ case $action in getTodo "$item" "$src" [ -z "$todo" ] && die "$item: No such item in $src." - if [ $TODOTXT_FORCE = 0 ]; then - echo "Move '$todo' from $src to $dest? (y/n)" - read -e -r ANSWER - else - ANSWER="y" - fi - if [ "$ANSWER" = "y" ]; then + if confirm "Move '$todo' from $src to $dest"; then if [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then # delete line (changes line numbers) sed -i.bak -e "${item}s/^.*//" -e '/./!d' "$src" From 2d70a0aadfca885ec49c734ab56d19cd1224ff31 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Mon, 9 Aug 2021 20:03:49 +0000 Subject: [PATCH 32/38] Minor fixes identified through shellcheck and other tools (#350) * fix whitespace * fix spelling * fix whitespace * unify headers of tests * fix some issues in tests, identified by shellcheck * fix bash completions bash completion files are not supposed to be executable * fix some issues identified by shellcheck Co-authored-by: Ali Karbassi --- CHANGELOG.md | 4 +- GEN-VERSION-FILE | 2 - LICENSE | 2 +- Makefile | 2 +- README.md | 4 +- USAGE.md | 10 +-- tests/README | 64 +++++++++---------- tests/actions-test-lib.sh | 2 +- tests/aggregate-results.sh | 12 ++-- tests/t0000-config.sh | 6 +- tests/t0001-null.sh | 1 - tests/t0002-actions.sh | 4 +- tests/t1020-addtolistfile.sh | 4 +- tests/t1100-replace.sh | 4 +- tests/t1300-ls.sh | 2 - tests/t1310-listcon.sh | 1 - tests/t1320-listproj.sh | 2 - tests/t1330-ls-highlighting.sh | 1 - tests/t1340-listescapes.sh | 1 - .../t1360-ls-project-context-highlighting.sh | 1 - ...80-ls-date-number-metadata-highlighting.sh | 2 - tests/t1500-do.sh | 1 + tests/t1600-append.sh | 2 +- tests/t1850-move.sh | 1 - tests/t2100-help.sh | 1 - tests/t2120-shorthelp.sh | 2 - tests/t2200-no-done-report-files.sh | 3 +- tests/t6000-completion.sh | 1 - tests/t6010-completion-contexts.sh | 1 - tests/t6020-completion-projects.sh | 1 - tests/t6030-completion-tasks.sh | 1 - tests/t6040-completion-files.sh | 1 - tests/t6050-completion-addons.sh | 3 +- tests/t6060-completion-addon-files.sh | 1 - tests/t6080-completion-path.sh | 3 - tests/t6090-completion-aliases.sh | 2 - tests/t6100-completion-help.sh | 1 - tests/test-lib.sh | 30 ++++----- todo.sh | 13 ++-- todo_completion | 8 ++- 40 files changed, 88 insertions(+), 119 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dde4cee..e10522b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -147,7 +147,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Changed odd tabs to spaces. -- Faster help/useage document outputs. +- Faster help/usage document outputs. - Consolidated `TODOTXT_VERBOSE` tests. - Refactored various add functionality to one function. - Updated `_list()` output to match updated `addto`. @@ -436,7 +436,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added -- `list` is case insenstive. ie, `todo list Mac` will match lines with "mac" and "Mac" +- `list` is case insensitive. ie, `todo list Mac` will match lines with "mac" and "Mac" ### Changed diff --git a/GEN-VERSION-FILE b/GEN-VERSION-FILE index 7821d60..6308d3e 100755 --- a/GEN-VERSION-FILE +++ b/GEN-VERSION-FILE @@ -34,5 +34,3 @@ test "$VN" = "$VC" || { echo >&2 "VERSION=$VN" echo "VERSION=$VN" >$VF } - - diff --git a/LICENSE b/LICENSE index e72bfdd..f288702 100644 --- a/LICENSE +++ b/LICENSE @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. \ No newline at end of file +. diff --git a/Makefile b/Makefile index 58c1e69..b6056bc 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,7 @@ $(TESTS): test-pre-clean test: aggregate-results tests/aggregate-results.sh tests/test-results/t*-* rm -rf tests/test-results - + # Force tests to get run every time .PHONY: test test-pre-clean aggregate-results $(TESTS) diff --git a/README.md b/README.md index af1fc36..4fc5128 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ See [CHANGELOG.md][CHANGELOG] ## Contributing -We welcome all contributations. First read our [Contributor Code of Conduct][CODE_OF_CONDUCT] and then get started [contributing][CONTRIBUTING]. +We welcome all contributions. First read our [Contributor Code of Conduct][CODE_OF_CONDUCT] and then get started [contributing][CONTRIBUTING]. ## License @@ -94,7 +94,7 @@ GNU General Public License v3.0 © [todo.txt org][github] [release]: https://github.com/todotxt/todo.txt-cli/releases -[website]: http://todotxt.org +[website]: http://todotxt.org/ [github]: https://github.com/todotxt [USAGE]: ./USAGE.md [CHANGELOG]: ./CHANGELOG.md diff --git a/USAGE.md b/USAGE.md index 3db9094..4500377 100644 --- a/USAGE.md +++ b/USAGE.md @@ -7,9 +7,9 @@ todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] ## Actions ### `add` -Adds THING I NEED TO DO to your todo.txt file on its own line. +Adds THING I NEED TO DO to your todo.txt file on its own line. -Project and context notation optional. +Project and context notation optional. Quotes optional. @@ -28,7 +28,7 @@ todo.sh addm "FIRST THING I NEED TO DO +project1 @context SECOND THING I NEED TO DO +project2 @context" ``` -### `addto` +### `addto` Adds a line of text to any file located in the todo.txt directory. For example, `addto inbox.txt "decide about vacation"` @@ -101,10 +101,10 @@ todo.sh help [ACTION...] ``` ### `list` -Displays all tasks that contain TERM(s) sorted by priority with line numbers. Each task must match all TERM(s) (logical AND); to display tasks that contain any TERM (logical OR), use `"TERM1\|TERM2\|..."` (with quotes), or `TERM1\\|TERM2` (unquoted). Hides all tasks that contain TERM(s) preceded by a minus sign (i.e. `-TERM`). +Displays all tasks that contain TERM(s) sorted by priority with line numbers. Each task must match all TERM(s) (logical AND); to display tasks that contain any TERM (logical OR), use `"TERM1\|TERM2\|..."` (with quotes), or `TERM1\\|TERM2` (unquoted). Hides all tasks that contain TERM(s) preceded by a minus sign (i.e. `-TERM`). If no TERM specified, lists entire todo.txt. -​ + ```shell todo.sh list [TERM...] todo.sh ls [TERM...] diff --git a/tests/README b/tests/README index d5fc70a..3f1740d 100644 --- a/tests/README +++ b/tests/README @@ -18,14 +18,14 @@ The easiest way to run tests is to say "make test" from the top-level. This runs all the tests. rm -rf tests/test-results "tests/trash directory"* - cd tests && sh t0000-config.sh + cd tests && sh t0000-config.sh * ok 1: no config file * ok 2: config file (default location 1) * ok 3: config file (default location 2) * ok 4: config file (command line) * ok 5: config file (env variable) * passed all 5 test(s) - cd tests && sh t0001-null.sh + cd tests && sh t0001-null.sh * ok 1: null ls * passed all 1 test(s) rm -rf tests/test-results @@ -33,7 +33,7 @@ This runs all the tests. Or you can run each test individually from command line, like this: - $ ./t0001-null.sh + $ ./t0001-null.sh * ok 1: null ls * passed all 1 test(s) @@ -42,27 +42,27 @@ You can pass --verbose (or -v), --debug (or -d), and --immediate appropriately before running "make". --verbose:: - This makes the test more verbose. Specifically, the - command being run and their output if any are also - output. + This makes the test more verbose. Specifically, the + command being run and their output if any are also + output. --debug:: - This may help the person who is developing a new test. - It causes the command defined with test_debug to run. + This may help the person who is developing a new test. + It causes the command defined with test_debug to run. --immediate:: - This causes the test to immediately exit upon the first - failed test. + This causes the test to immediately exit upon the first + failed test. --long-tests:: - This causes additional long-running tests to be run (where - available), for more exhaustive testing. + This causes additional long-running tests to be run (where + available), for more exhaustive testing. --tee:: - In addition to printing the test output to the terminal, - write it to files named 't/test-results/$TEST_NAME.out'. - As the names depend on the tests' file names, it is safe to - run the tests with this option in parallel. + In addition to printing the test output to the terminal, + write it to files named 't/test-results/$TEST_NAME.out'. + As the names depend on the tests' file names, it is safe to + run the tests with this option in parallel. Skipping Tests -------------- @@ -97,15 +97,15 @@ Naming Tests The test files are named as: - tNNNN-commandname-details.sh + tNNNN-commandname-details.sh where N is a decimal digit. First digit tells the family: - 0 - the absolute basics and global stuff - 1 - basic every-day usage - 2 - add ins + 0 - the absolute basics and global stuff + 1 - basic every-day usage + 2 - add ins Second digit tells the particular command we are testing. @@ -128,15 +128,15 @@ The test script is written as a shell script. It should start with the standard "#!/bin/bash" with copyright notices, and an assignment to variable 'test_description', like this: - #!/bin/bash - # - # Copyright (c) 2005 Junio C Hamano - # + #!/bin/bash + # + # Copyright (c) 2005 Junio C Hamano + # - test_description='xxx test (option --frotz) + test_description='xxx test (option --frotz) - This test registers the following structure in the cache - and tries to run git-ls-files with option --frotz.' + This test registers the following structure in the cache + and tries to run git-ls-files with option --frotz.' Source 'test-lib.sh' @@ -145,7 +145,7 @@ Source 'test-lib.sh' After assigning test_description, the test script should source test-lib.sh like this: - . ./test-lib.sh + . ./test-lib.sh This test harness library does the following things: @@ -219,9 +219,9 @@ library for your script to use. Example: - test_expect_success \ - 'git-write-tree should be able to write an empty tree.' \ - 'tree=$(git-write-tree)' + test_expect_success \ + 'git-write-tree should be able to write an empty tree.' \ + 'tree=$(git-write-tree)' - test_expect_code