Created
January 18, 2018 17:15
-
-
Save rjz/80d0b5f4f461433fa5a3f3f2fb2b6a32 to your computer and use it in GitHub Desktop.
TODO git hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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