Skip to content

Instantly share code, notes, and snippets.

@samstokes samstokes/todo
Last active Nov 2, 2018

Embed
What would you like to do?
A todo management system in a gist
#!/bin/bash -e
if [[ $# > 0 ]]; then
case "$1" in
-h | -\? | --help )
{
echo "Add a todo:"
echo " todo Reformulate the widget plans."
echo "See what you have to do:"
echo " todo"
echo "After you've done item 4:"
echo " todo -4"
echo "Count items left to do:"
echo " todo -c"
echo "Edit the todo list directly (using $EDITOR):"
echo " todo -e"
} >&2
;;
-c | --count )
if [ -r TODO ]; then
exec wc -l TODO
else
echo 0 TODO
fi
;;
-e | --edit )
shift
exec $EDITOR TODO "$@"
;;
-* | x* )
lineno=$(cut -c2- <<<"$1")
sed -i "$lineno d" TODO
echo Deleted item $lineno. >&2
echo
exec "$0"
;;
* )
echo "$@" >> TODO
;;
esac
elif [ -r TODO ]; then
if grep -q . TODO; then
awk 'BEGIN { n = 1 } { printf "[%d]\t%s\n", n, $0; n = n + 1 }' TODO
else
echo Nothing to do!
fi
else
echo Nothing to do!
fi
@samstokes

This comment has been minimized.

Copy link
Owner Author

samstokes commented Apr 16, 2013

If I'm working on something in a terminal (coding, code review, documenting), I often want somewhere to jot down things I just thought of, so I can come back to them later. They tend to be too fine-grained / low-level / transient to keep in a proper task manager or bug tracker. A file in the working directory is just right.

This makes it a tiny bit easier to maintain such a file, without sacrificing the power of plain text. Want to filter tasks? grep. Need to edit or reorder? $EDITOR is there for you.

It's also, I think, a nice example of how useful - and readable - a brief shell script can be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.