Skip to content

Commit

Permalink
Merge branch 'mivok/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Aug 26, 2009
2 parents e0b3ea1 + 98569d5 commit 266d9e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
13 changes: 11 additions & 2 deletions tests/t0000-config.sh
Expand Up @@ -10,7 +10,7 @@ to find it somewhere else.

# Remove the pre-created todo.cfg to test behavior in its absence
rm -f todo.cfg
echo "Fatal error: Cannot read configuration file $HOME/todo.cfg" > expect
echo "Fatal error: Cannot read configuration file $HOME/.todo/config" > expect
test_expect_success 'no config file' '
todo.sh > output 2>&1 || test_cmp expect output
'
Expand All @@ -32,14 +32,23 @@ EOF

rm -f used_config
test_expect_success 'config file (default location 1)' '
mkdir .todo
cp test.cfg .todo/config
todo.sh > output;
test_cmp expect output && test -f used_config &&
rm -rf .todo
'

rm -f used_config
test_expect_success 'config file (default location 2)' '
cp test.cfg todo.cfg
todo.sh > output;
test_cmp expect output && test -f used_config &&
rm -f todo.cfg
'

rm -f used_config
test_expect_success 'config file (default location 2)' '
test_expect_success 'config file (default location 3)' '
cp test.cfg .todo.cfg
todo.sh > output;
test_cmp expect output && test -f used_config &&
Expand Down
28 changes: 23 additions & 5 deletions todo.sh
@@ -1,7 +1,7 @@
#! /bin/bash

# NOTE: Todo.sh requires the todo.cfg configuration file to run.
# Place the todo.cfg file in your home directory or use the -d option for a custom location.
# 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.

[ -f VERSION-FILE ] && . VERSION-FILE || VERSION="@DEV_VERSION@"
version() { sed -e 's/^ //' <<EndVersion
Expand Down Expand Up @@ -172,7 +172,7 @@ help()
Hide project names in list output. Use twice to show project
names (default).
-d CONFIG_FILE
Use a configuration file other than the default ~/todo.cfg
Use a configuration file other than the default ~/.todo/config
-f
Forces actions without confirmation or interactive input
-h
Expand Down Expand Up @@ -341,7 +341,7 @@ 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.cfg}
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}
Expand Down Expand Up @@ -379,6 +379,15 @@ export PRI_B=$GREEN # color for B priority
export PRI_C=$LIGHT_BLUE # color for C priority
export PRI_X=$WHITE # color for rest of them

[ -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="$HOME/.todo.cfg"

Expand All @@ -390,10 +399,19 @@ export PRI_X=$WHITE # color for rest of them

if [ -z "$TODO_ACTIONS_DIR" -o ! -d "$TODO_ACTIONS_DIR" ]
then
TODO_ACTIONS_DIR="$HOME/.todo.actions.d"
TODO_ACTIONS_DIR="$HOME/.todo/actions"
export TODO_ACTIONS_DIR
fi

[ -d "$TODO_ACTIONS_DIR" ] || {
TODO_ACTIONS_DIR_ALT="$HOME/.todo.actions.d"

if [ -d "$TODO_ACTIONS_DIR_ALT" ]
then
TODO_ACTIONS_DIR="$TODO_ACTIONS_DIR_ALT"
fi
}

# === SANITY CHECKS (thanks Karl!) ===
[ -r "$TODOTXT_CFG_FILE" ] || die "Fatal error: Cannot read configuration file $TODOTXT_CFG_FILE"

Expand Down

0 comments on commit 266d9e1

Please sign in to comment.