Skip to content

Instantly share code, notes, and snippets.

@zph
Created October 19, 2015 16:30
Show Gist options
  • Select an option

  • Save zph/95249ad4816d3ca0b1ae to your computer and use it in GitHub Desktop.

Select an option

Save zph/95249ad4816d3ca0b1ae to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Credit: 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() {
git ls-files -z | \
xargs -0 grep -InR 'TODO'
}
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