Skip to content

Instantly share code, notes, and snippets.

@timofurrer
Created August 20, 2013 09:02
Show Gist options
  • Save timofurrer/6279011 to your computer and use it in GitHub Desktop.
Save timofurrer/6279011 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "$1" ]; then
echo Error: please specify a file >&2
exit 1
fi
for f in $@; do
if [ ! -f "$f" ]; then
echo "Error: file '$f' does not exist" >&2
exit 2
fi
lines=`cat "$f" | wc -l`
echo "Blame stats for $f"
echo "Percentage Lines Author"
echo ============================================
git blame --line-porcelain "$f" | sed -n 's/^author //p' | sort | uniq -c | sort -rn | awk -v lines=$lines '{ percentage = 100/lines*$1; sub(/^[ \t]+/,"", $0); sub(/[ \t]+$/,"", $0); printf "%5.2f %% %4d l ", percentage, $1; $1 = ""; print $0; }'
echo ============================================
echo Lines of file $lines
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment