Created
November 7, 2015 21:47
-
-
Save philcryer/ff8eb56b5dcd872f2ec7 to your computer and use it in GitHub Desktop.
Using git to manage 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 | |
# Using Git to Manage Todos | |
# by Jezen Thomas | |
# http://jezenthomas.com/using-git-to-manage-todos/ | |
set -e | |
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