Skip to content

Instantly share code, notes, and snippets.

@Sonictherocketman
Last active May 20, 2024 22:38
Show Gist options
  • Save Sonictherocketman/77dd6cd8fd907dbbc00031acb08f3ba0 to your computer and use it in GitHub Desktop.
Save Sonictherocketman/77dd6cd8fd907dbbc00031acb08f3ba0 to your computer and use it in GitHub Desktop.
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"
sep=$(printf %"$(tput cols)"s |tr " " "-")
# 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
$sep
todolist
cwd: $(basename $DIR)
types: $TYPES
$sep
$lines
EOF
sleep 10;
done;
@Sonictherocketman
Copy link
Author

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

@Sonictherocketman
Copy link
Author

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

@Sonictherocketman
Copy link
Author

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