Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Create a continuously updated todo list from code comments. https://brianschrader.com/archive/todolist/
#! /bin/bash
# Given the current working directory, find all of the files of the
# type given and search for TODO comments in them and return a list
# of these items.
#
# Usage: todolist <dir> '*.py'
DIR=$1
if [ -z "$DIR" ]; then
DIR="."
fi
TYPES=$2
if [ -z "$TYPES" ]; then
TYPES='*.py'
fi
INDENT=" "
get_results() {
file=$1
todos=$(cat "$file" | nl | grep -i 'TODO' "$file");
echo "$todos" | while read todo; do
if [ -n "$todo" ]; then
text=$(echo "$todo" | sed 's/.*TODO[: ]*\(.*\)/\1/');
if [ -z "$text" ]; then
printf "$INDENT- [Blank]\n"
else
printf "$INDENT- $text\n"
fi
fi
done
}
# Set the window title
# http://bit.ly/2k3BtgN
echo -n -e "\033]0;todolist\007"
# Process Files
while true; do
lines=$(find "$DIR" -name "$TYPES" -type f | while read file; do
results=$(get_results "$file");
if [ -n "$results" ]; then
printf "$file\n$results\n\n"
fi
done);
# Clear scrollback and render
printf "\033c";
echo "$lines";
sleep 5;
done;

Sweet! This is awesome. Using it.

I noticed my projects have inconsistent todo format ("to do:", "TODO:") so I forked and tweaked the matching a little bit. Also limited it to looking at comments since I got a couple matches on non-comments.

I've updated it with some new pretty printed output, and removed that pesky temp file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment