Display todo.txt
items by project instead of by date.
I discovered and began using todo.txt in August 2016 to keep track of my to-do items in the context of various projects by tagging items with +<projectname>
. My preferred method of interaction is the todo.txt command line interface. I have found a number of add-ons to be useful, particularly add, xp, and pri. However, I often want to display items organized by project, and have not found an add-on that will do this. Hence this python script.
As a side note, Michael Descy's Plaintext Productivity has many useful ideas for text file-based personal organization and productivity.
- Python 3.x
- I recommend installing Anaconda as the simplest, most hassle-free route to using python.
- Mac OS (Linux is probably fine too, but I haven't tested it)
- Download
byproject.py
. This is the only file you need. It uses thecolorama
package, which is included by default in the standardAndaconda
install. - Copy
byproject.py
to any convenient directory in your file system.
- Modify the shebang on line 1,
#!/usr/bin/env python3.5
, as needed to point to your python installation. It tells the operating system what to use to executebyproject.py
. See answers to this StackOverflow question for an explanation. - Modify lines 233 and 235 to point to your
done.txt
andtodo.txt
files, respectively. - In Terminal, make the directory where you put
byproject.py
the current working directory and executechmod +x byproject.py
. This indicates to the operating system thatbyproject.py
is a file that can be directly executed.
I find it convenient to define several aliases in my .bash_profile
. Here is what I use:
alias bp='~/Documents/Projects/todo/byproject.py'
alias bpt='~/Documents/Projects/todo/byproject.py -p 0' # Today's done items
Given the first alias, executing bp -h
prints the following help text:
usage: byproject.py [-h] [-f FILE] [-v]
[-p PREV | -d DAY | -m MONTH | -w WEEK | -r RANGE RANGE | -a]
[-i INCLUDE [INCLUDE ...] | -x EXCLUDE [EXCLUDE ...]]
optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE Specify input file name (and path), FILE
-v, --verbose Print extra debug information
-p PREV, --prev PREV Number of days previous, PREV=N, to today to include
-d DAY, --day DAY Particular day, DAY=YYYY-MM-DD
-m MONTH, --month MONTH
Specified month, MONTH=YYYY-MM
-w WEEK, --week WEEK Week starting from specified day, WEEK=YYYY-MM-DD
-r RANGE RANGE, --range RANGE RANGE
Range of dates, RANGE=YYYY-MM-DD
-a, --all Process all days in file
-i INCLUDE [INCLUDE ...], --include INCLUDE [INCLUDE ...]
Include specified projects
-x EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]
Exclude specified projects
Show contents of todo.txt
by project
bp
Show items in todo.txt
with project tags "proposals" and "whitepapers"
bp -i projectname1 projectname2
Show items in todo.txt
except for those with project tag "personal" and "home"
bp -x projectname1 projectname2
Show items for today in done.txt
bp -p 0
Show items for last 3 days in done.txt
bp -p 3
Show items for last week in temp.txt
bp -p 7 -f temp.txt
Show items for last week in done.txt
with project tag "make3dprinter"
bp -p 7 -i make3dprinter
Show items for last week in temp.txt
with project tag "make3dprinter"
bp -p 7 -i make3dprinter -f temp.txt
Show items for last week in done.txt
except for those with project tag "groceries"
bp -p 7 -x groceries
Show all items in done.txt
bp -a
Show items for specified day in done.txt
bp -d YYYY-MM-DD
Show items for week starting on specified day in done.txt
bp -w YYYY-MM-DD
Show items for month in done.txt
bp -m YYYY-MM
Show items in specified date range in done.txt
bp -r YYYY-MM-DD YYYY-MM-DD
Show items in specified date range in done.txt
with project tag "make3dprinter"
bp -r YYYY-MM-DD YYYY-MM-DD -i make3dprinter
- I use only one project tag per todo item.
byproject.py
has been designed with this in mind. - The
todo.txt
anddone.txt
files are sorted by date in ascending order.
In my .bash_profile
file I have included the following function definition to find, count, and list the unique project tags in a text file in descending order of occurrence.
# Create function to list all projects in descending order with number
# of occurrences for any file with the default file being done.txt
listproj() {
if [ $# -eq 0 ];
then
cut -d'+' -f2 /Users/nordin/Dropbox/todo/done.txt | cut -d' ' -f1 | sort | uniq -c | sort -nr
else
cut -d'+' -f2 $1 | cut -d' ' -f1 | sort | uniq -c | sort -nr
fi
}
I also use the following function with todo.sh
rather than creating an alias so that it gracefully handles all possible flags.
# Set up todo.sh to use with Dropbox such that all flags work
# From http://stackoverflow.com/questions/7131670/make-bash-alias-that-takes-parameter
# and http://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value
t() {
# If argument starts with "-" (like "t -h") put it in the middle of command
if [[ $1 == -* ]] ;
then
/Users/nordin/Dropbox/todo/todo.sh $1 -d /Users/nordin/Dropbox/todo/todo.cfg;
# Otherwise, put it at end of command (like "t list")
else
/Users/nordin/Dropbox/todo/todo.sh -d /Users/nordin/Dropbox/todo/todo.cfg $@;
fi
}