From 3d308a6f79c3160f01e9ae4db3526d29aa6c09d6 Mon Sep 17 00:00:00 2001 From: 85 Date: Mon, 30 Mar 2020 02:33:16 +0700 Subject: [PATCH] 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"