Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local todo.txt for project specific task lists #187

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions todo.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
#export TODO_DIR="/Users/gina/Documents/todo"
export TODO_DIR=$(dirname "$0")

# Your todo/done/report.txt locations
export TODO_FILE="$TODO_DIR/todo.txt"
export DONE_FILE="$TODO_DIR/done.txt"
export REPORT_FILE="$TODO_DIR/report.txt"
# You can override your todo/done/report.txt locations here.
# These will override TODOTXT_USE_LOCAL=1; it doesn't make sense for TODO_FILE,
# but you could override DONE_FILE / REPORT_FILE in order to
# collect done tasks / reports globally.
#
#export TODO_FILE="$TODO_DIR/todo.txt"
#export DONE_FILE="$TODO_DIR/done.txt"
#export REPORT_FILE="$TODO_DIR/report.txt"

# You can customize your actions directory location
#export TODO_ACTIONS_DIR="$HOME/.todo.actions.d"
Expand Down Expand Up @@ -82,3 +86,9 @@ export REPORT_FILE="$TODO_DIR/report.txt"
# just before the list output is displayed.
#
# export TODOTXT_FINAL_FILTER='cat'

# TODOTXT_USE_LOCAL will look for a todo.txt up the directory tree
# and use this directory as TODO_DIR when found.
# Useful for project-specific todo lists.
#
# export TODOTXT_USE_LOCAL=1
37 changes: 36 additions & 1 deletion todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ help()
Color mode
-d CONFIG_FILE
Use a configuration file other than the default ~/.todo/config
-l
Use a (local) todo.txt that is found in the current directory
or up the directory tree, falling back to the configured (global)
TODO_DIR if no local one is found
-L
Use global todo.txt from the config file, not the local one
(default).
-f
Forces actions without confirmation or interactive input
-h
Expand Down Expand Up @@ -141,6 +148,7 @@ help()
TODOTXT_AUTO_ARCHIVE is same as option -a (0)/-A (1)
TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE
TODOTXT_FORCE=1 is same as option -f
TODOTXT_USE_LOCAL is same as option -l (0)/-L (1)
TODOTXT_PRESERVE_LINE_NUMBERS is same as option -n (0)/-N (1)
TODOTXT_PLAIN is same as option -p (1)/-c (0)
TODOTXT_DATE_ON_ADD is same as option -t (1)/-T (0)
Expand Down Expand Up @@ -476,12 +484,13 @@ OVR_TODOTXT_VERBOSE="$TODOTXT_VERBOSE"
OVR_TODOTXT_DEFAULT_ACTION="$TODOTXT_DEFAULT_ACTION"
OVR_TODOTXT_SORT_COMMAND="$TODOTXT_SORT_COMMAND"
OVR_TODOTXT_FINAL_FILTER="$TODOTXT_FINAL_FILTER"
OVR_TODOTXT_USE_LOCAL="$TODOTXT_USE_LOCAL"

# Prevent GREP_OPTIONS from malforming grep's output
GREP_OPTIONS=""

# == PROCESS OPTIONS ==
while getopts ":fhpcnNaAtTvVx+@Pd:" Option
while getopts ":fhpcnNaAlLtTvVx+@Pd:" Option
do
case $Option in
'@' )
Expand Down Expand Up @@ -538,6 +547,12 @@ do
set -- '-h' 'shorthelp'
OPTIND=2
;;
l )
OVR_TODOTXT_USE_LOCAL=1
;;
L )
OVR_TODOTXT_USE_LOCAL=0
;;
n )
OVR_TODOTXT_PRESERVE_LINE_NUMBERS=0
;;
Expand Down Expand Up @@ -595,6 +610,7 @@ 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}
TODOTXT_USE_LOCAL=${TODOTXT_USE_LOCAL:-0}

# Export all TODOTXT_* variables
export ${!TODOTXT_@}
Expand Down Expand Up @@ -726,9 +742,28 @@ fi
if [ -n "$OVR_TODOTXT_FINAL_FILTER" ] ; then
TODOTXT_FINAL_FILTER="$OVR_TODOTXT_FINAL_FILTER"
fi
if [ -n "$OVR_TODOTXT_USE_LOCAL" ] ; then
TODOTXT_USE_LOCAL="$OVR_TODOTXT_USE_LOCAL"
fi

ACTION=${1:-$TODOTXT_DEFAULT_ACTION}

if [ $TODOTXT_USE_LOCAL -gt 0 ]; then
# search for todo.txt up the directory tree
S="${PWD}"
while [ -n "${S}" ] && [ ! -f "${S}/todo.txt" ] ; do
S=${S%/*}
done
# if found before reaching root, this is the TODO_DIR
if [ -n "${S}" ] ; then
TODO_DIR="${S}"
fi
fi

TODO_FILE=${TODO_FILE:-"$TODO_DIR/todo.txt"}
DONE_FILE=${DONE_FILE:-"$TODO_DIR/done.txt"}
REPORT_FILE=${REPORT_FILE:-"$TODO_DIR/report.txt"}

[ -z "$ACTION" ] && usage
[ -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"
Expand Down