Allow the use of global config file

If not found elsewhere, look for the config file in /etc/todo/config.
`make install` installs a global config file, setting TODO_DIR=~/.todo.
todo.sh creates TODO_DIR if it doesn't exist.
This commit is contained in:
Manuel J. Garrido
2013-06-24 10:32:42 +02:00
parent 93d8e16d50
commit ce365df67c
4 changed files with 29 additions and 4 deletions

12
todo.sh
View File

@@ -584,6 +584,7 @@ TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
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}
# Export all TODOTXT_* variables
export ${!TODOTXT_@}
@@ -650,6 +651,15 @@ export SENTENCE_DELIMITERS=',.:;'
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
}
if [ -z "$TODO_ACTIONS_DIR" -o ! -d "$TODO_ACTIONS_DIR" ]
then
@@ -706,7 +716,7 @@ fi
ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
[ -z "$ACTION" ] && usage
[ -d "$TODO_DIR" ] || dieWithHelp "$1" "Fatal Error: $TODO_DIR is not a directory"
[ -d "$TODO_DIR" ] || mkdir -p $TODO_DIR 2> /dev/null || dieWithHelp "$1" "Fatal Error: $TODO_DIR is not a directory"
( cd "$TODO_DIR" ) || dieWithHelp "$1" "Fatal Error: Unable to cd to $TODO_DIR"
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"