Skip to content

Instantly share code, notes, and snippets.

@mc706
Last active October 19, 2015 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mc706/1bf3cd89cfb2ffe92b4e to your computer and use it in GitHub Desktop.
Save mc706/1bf3cd89cfb2ffe92b4e to your computer and use it in GitHub Desktop.
a quick one off bash script to total hours in commit messages matching Time: [1.5] pattern per user
#!/usr/bin/env bash
OIFS=$IFS;
IFS=$'\n';
TAGS=$(git log --tags --simplify-by-decoration --pretty="format:%ci %d" | grep -o "\(tag:\s[v0-9\.]*\)" | sed "s/tag: //g")
CONTRIBUTORS=$(git shortlog -e -s | grep -o "<.*>"| sed 's/[<>]//g');
OUTPUT=()
HEADER=("CONTRIBUTORS")
for name in $CONTRIBUTORS
do
HEADER=$(echo $HEADER $'\t' $name)
done
OUTPUT+=($HEADER)
last=""
for tag in $TAGS
do
tagline="$tag"
for name in $CONTRIBUTORS
do
CONTRIB=$(git log $tag..$last --author=$name --grep="^Time:" | grep -o "\[.*\]" | sed 's/\[//g' | sed 's/\]//g')
TOTAL=0
for time in $CONTRIB
do
TOTAL=$(echo "$TOTAL+$time" | bc)
done;
tagline=$(echo $tagline $'\t' $TOTAL)
done
last=$tag
OUTPUT+=($tagline)
done
totalline="TOTAL"
for name in $CONTRIBUTORS
do
CONTRIB=$(git log --author=$name --grep="^Time:" | grep -o "\[.*\]" | sed 's/\[//g' | sed 's/\]//g')
TOTAL=0
for time in $CONTRIB
do
TOTAL=$(echo "$TOTAL+$time" | bc)
done;
totalline=$(echo $totalline $'\t' $TOTAL)
done;
OUTPUT+=($totalline)
for line in ${OUTPUT[@]}
do
echo $line
done | column -t -s $'\t'
IFS=$OIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment