Skip to content

Commit

Permalink
Allow overriding AGAIN_TAG from environment variable (#19)
Browse files Browse the repository at this point in the history
* Allow overriding AGAIN_TAG from environment

* Add test case for overriding again tag with environment variable
  • Loading branch information
ad1217 authored and nthorne committed Oct 3, 2018
1 parent 3f8617a commit 898dc4f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ will only re-add tasks that have an again tag in them, making the again command
a drop-in replacement for the `do` command for any tasks without the again tag.
See Examples for usage.

The environment variable `TODO_AGAIN_TAG` can be set to change the tag
which is used for the adjustment interval if present.

# Examples

Here are some examples that demonstrate how the again add-on works.
Expand Down
2 changes: 1 addition & 1 deletion again
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ source `dirname $0`/againHelpers.sh

readonly SED_DATE_RE="[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}"
readonly BASH_DATE_RE="[0-9]{4}-[0-9]{2}-[0-9]{2}"
readonly AGAIN_TAG="again"
readonly AGAIN_TAG="${TODO_AGAIN_TAG:-again}"

function usage()
{
Expand Down
1 change: 1 addition & 0 deletions test/sample.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ This is the first line
(A) 2013-01-01 This is the eighth line
Line 9 due:2015-08-15
(A) 2013-03-03 This is the tenth line due:2013-03-03 t:2013-02-02 again:+10
2013-03-03 This is the eleventh line due:2013-03-03 t:2013-02-02 repeat:+2
17 changes: 17 additions & 0 deletions test/testAgain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ function test_command_line_overrides_again_tag()
TEST_FAILS=$(($TEST_FAILS + $?))
}

function test_environment_variable_overrides_again_tag()
{
TASK=11
export TODO_AGAIN_TAG=repeat
if [[ "GNU" == $DATE_VERSION ]]
then
expected=("command_do_$TASK" "command_add_`date +%F`_This_is_the_eleventh_line_due:`date -d '2013-03-03 +2 days' +%F`_t:`date -d '2013-02-02 +2 days' +%F`_repeat:+2")
else
expected=("command_do_$TASK" "command_add_`date +%F`_This_is_the_eleventh_line_due:`date -j -v+2d -f %F 2013-03-03 +%F`_t:`date -j -v+2d -f %F 2013-02-02 +%F`_repeat:+2")
fi
export TEST_EXPECT=`echo ${expected[@]}`
$AGAIN $TASK
TEST_FAILS=$(($TEST_FAILS + $?))
unset TODO_AGAIN_TAG
}

function test_day_stepping()
{
TASK=9
Expand Down Expand Up @@ -388,6 +404,7 @@ test_line_with_creation_date_and_prio
test_nonexisting_line
test_line_with_again_tag
test_command_line_overrides_again_tag
test_environment_variable_overrides_again_tag
test_day_stepping
test_week_stepping
test_month_stepping
Expand Down

0 comments on commit 898dc4f

Please sign in to comment.