Skip to content

Instantly share code, notes, and snippets.

Embed
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 -e '\bTODO\b:' "$file");
echo "$todos" | while read todo; do
if [ -n "$todo" ]; then
text=$(echo "$todo" | sed 's/.*TODO[: ]*\(.*\) \(-->\)\{0,1\}/\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";
cat << EOF
--------------------------------------------------------
todolist
--------------------------------------------------------
$lines
EOF
sleep 10;
done;
@adam-operatingops

This comment has been minimized.

Copy link

@adam-operatingops adam-operatingops commented Oct 9, 2017

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.

@Sonictherocketman

This comment has been minimized.

Copy link
Owner Author

@Sonictherocketman Sonictherocketman commented Oct 10, 2017

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

@Sonictherocketman

This comment has been minimized.

Copy link
Owner Author

@Sonictherocketman Sonictherocketman commented Sep 6, 2019

Fix: New version doesn't detect words with todo in them (i.e. mastodon)

@Sonictherocketman

This comment has been minimized.

Copy link
Owner Author

@Sonictherocketman Sonictherocketman commented Jul 21, 2020

New version. This one strips ending comments from HTML comments.

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