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
This commit is contained in:
2
USAGE.md
2
USAGE.md
@@ -221,7 +221,7 @@ Hide project names in list output. Use twice to show project names (default).
|
|||||||
Color mode
|
Color mode
|
||||||
|
|
||||||
### `-d CONFIG_FILE`
|
### `-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`
|
### `-f`
|
||||||
Forces actions without confirmation or interactive input.
|
Forces actions without confirmation or interactive input.
|
||||||
|
|||||||
81
todo.sh
81
todo.sh
@@ -3,8 +3,8 @@
|
|||||||
# === HEAVY LIFTING ===
|
# === HEAVY LIFTING ===
|
||||||
shopt -s extglob extquote
|
shopt -s extglob extquote
|
||||||
|
|
||||||
# NOTE: Todo.sh requires the .todo/config configuration file to run.
|
# NOTE: Todo.sh requires a configuration file to run.
|
||||||
# Place the .todo/config file in your home directory or use the -d option for a custom location.
|
# 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@"
|
[ -f VERSION-FILE ] && . VERSION-FILE || VERSION="@DEV_VERSION@"
|
||||||
version() {
|
version() {
|
||||||
@@ -83,6 +83,8 @@ shorthelp()
|
|||||||
|
|
||||||
help()
|
help()
|
||||||
{
|
{
|
||||||
|
local indentedJoinedConfigFileLocations
|
||||||
|
printf -v indentedJoinedConfigFileLocations ' %s\n' "${configFileLocations[@]}"
|
||||||
cat <<-EndOptionsHelp
|
cat <<-EndOptionsHelp
|
||||||
Usage: $oneline_usage
|
Usage: $oneline_usage
|
||||||
|
|
||||||
@@ -96,7 +98,8 @@ help()
|
|||||||
-c
|
-c
|
||||||
Color mode
|
Color mode
|
||||||
-d CONFIG_FILE
|
-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
|
-f
|
||||||
Forces actions without confirmation or interactive input
|
Forces actions without confirmation or interactive input
|
||||||
-h
|
-h
|
||||||
@@ -616,7 +619,6 @@ shift $((OPTIND - 1))
|
|||||||
# defaults if not yet defined
|
# defaults if not yet defined
|
||||||
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1}
|
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1}
|
||||||
TODOTXT_PLAIN=${TODOTXT_PLAIN:-0}
|
TODOTXT_PLAIN=${TODOTXT_PLAIN:-0}
|
||||||
TODOTXT_CFG_FILE=${TODOTXT_CFG_FILE:-$HOME/.todo/config}
|
|
||||||
TODOTXT_FORCE=${TODOTXT_FORCE:-0}
|
TODOTXT_FORCE=${TODOTXT_FORCE:-0}
|
||||||
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
|
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
|
||||||
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-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.
|
# (todo.sh add 42 ", foo") syntactically correct.
|
||||||
export SENTENCE_DELIMITERS=',.:;'
|
export SENTENCE_DELIMITERS=',.:;'
|
||||||
|
|
||||||
[ -e "$TODOTXT_CFG_FILE" ] || {
|
configFileLocations=(
|
||||||
CFG_FILE_ALT="$HOME/todo.cfg"
|
"$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" ]
|
if [ -e "$CFG_FILE_ALT" ]
|
||||||
then
|
then
|
||||||
TODOTXT_CFG_FILE="$CFG_FILE_ALT"
|
TODOTXT_CFG_FILE="$CFG_FILE_ALT"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
}
|
done
|
||||||
|
|
||||||
[ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if [ -z "$TODO_ACTIONS_DIR" ] || [ ! -d "$TODO_ACTIONS_DIR" ]
|
if [ -z "$TODO_ACTIONS_DIR" ] || [ ! -d "$TODO_ACTIONS_DIR" ]
|
||||||
@@ -728,26 +703,20 @@ then
|
|||||||
export TODO_ACTIONS_DIR
|
export TODO_ACTIONS_DIR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -d "$TODO_ACTIONS_DIR" ] || {
|
[ -d "$TODO_ACTIONS_DIR" ] || for TODO_ACTIONS_DIR_ALT in \
|
||||||
TODO_ACTIONS_DIR_ALT="$HOME/.todo.actions.d"
|
"$HOME/.todo.actions.d" \
|
||||||
|
"${XDG_CONFIG_HOME:-$HOME/.config}/todo/actions"
|
||||||
|
do
|
||||||
if [ -d "$TODO_ACTIONS_DIR_ALT" ]
|
if [ -d "$TODO_ACTIONS_DIR_ALT" ]
|
||||||
then
|
then
|
||||||
TODO_ACTIONS_DIR="$TODO_ACTIONS_DIR_ALT"
|
TODO_ACTIONS_DIR="$TODO_ACTIONS_DIR_ALT"
|
||||||
|
break
|
||||||
fi
|
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!) ===
|
# === 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"
|
. "$TODOTXT_CFG_FILE"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user