Source Code TODO Lists from the Command Line
This awk one-liner parses your source files for TODO comments after any comment indicator character(s) and prints the message by line number to the standard output stream. This article shows you how to define an awk shell alias with this command to print all TODO items to the standard output stream withtodo [file path]
.
Usage
$ awk '/TODO/ {print NR "\t" ($1=$2="") $0}' [source file path]
Example
Python source (pydoc.py)
Command line
$ awk '/TODO/ {print NR "\t" ($1=$2="") $0}' pydoc.py
5 this needs a lot of this and that
10 more things that I need to do
Modify
Change the regular expression /TODO/ in the awk command to whatever character format you use for the beginning of TODO list comments in your files.
Simplify
Add a new todo
alias to your shell runcom file (e.g. .bashrc, .zshrc) by including the following alias definition in the file:
alias todo="awk '/TODO/ {print NR \"\\t\" (\$1=\$2=\"\") \$0}'"
Note that the above line was modified with new character escapes and quote formatting that was not present in the original command.
Then source your runcom file. For bash:
$ source ~/.bashrc
And use your new alias at the command line like this:
$ todo pydoc.py
5 this needs a lot of this and that
10 more things that I need to do