Skip to content

Instantly share code, notes, and snippets.

@Sonictherocketman
Last active February 1, 2024 16:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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"
# 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;
@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