Skip to content

Instantly share code, notes, and snippets.

@rjz
Created January 18, 2018 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjz/80d0b5f4f461433fa5a3f3f2fb2b6a32 to your computer and use it in GitHub Desktop.
Save rjz/80d0b5f4f461433fa5a3f3f2fb2b6a32 to your computer and use it in GitHub Desktop.
TODO git hook
#!/bin/bash
# A pre-commit hook to help you do the right thing (tm)
set -e
changed-files () {
git diff HEAD --name-only "$@"
}
existing-file-todo () {
git blame -f $1 2> /dev/null \
| grep ^00000000 \
| cut -f2,9- -d' ' \
| grep TODO \
| sed 's/)//'
}
new-file-todo () {
nl $1 \
| grep TODO \
| sed "s:^ *:$f :"
}
still-todo() {
for f in $(changed-files); do
existing-file-todo $f || new-file-todo $f
done
}
TODOS=$(still-todo | sed 's/^/ - /')
if [[ ! -z $TODOS ]]; then
echo
echo "New TODOs! (Please consider Just Doing Them™)"
echo "---------------------------------------------"
echo "$TODOS"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment