Created
November 3, 2015 19:39
-
-
Save thomd/70d9ecaab35e4cd22919 to your computer and use it in GitHub Desktop.
post commit hook for TODOs
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 | |
set -e | |
# source: http://jezenthomas.com/using-git-to-manage-todos/ | |
main() { | |
while IFS= read -r todo; do | |
printf "%s\n" "$(file_path):$(line_number) $(line_author) $(message)" | |
done < <(todo_list) | |
} | |
todo_list() { | |
grep -InR 'TODO' ./* \ | |
--exclude-dir=node_modules \ | |
--exclude-dir=public \ | |
--exclude-dir=vendor \ | |
--exclude-dir=compiled \ | |
--exclude-dir=git-hooks | |
} | |
line_author() { | |
LINE=$(line_number "$todo") | |
FILE=$(file_path "$todo") | |
tput setaf 6 | |
printf "%s" "$(git log --pretty=format:"%cN" -s -L "$LINE","$LINE":"$FILE" | head -n 1)" | |
tput sgr0 | |
} | |
file_path() { | |
printf "%s" "$todo" | cut -d':' -f 1 | |
} | |
line_number() { | |
printf "%s" "$todo" | cut -d':' -f 2 | |
} | |
message() { | |
printf "%s" "$todo" | cut -d':' -f 3 | xargs | |
} | |
main | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment