Skip to content

Instantly share code, notes, and snippets.

@zeveshe
Last active August 29, 2015 14:23
Show Gist options
  • Save zeveshe/cc98f5bbdfcbc929722e to your computer and use it in GitHub Desktop.
Save zeveshe/cc98f5bbdfcbc929722e to your computer and use it in GitHub Desktop.
Git contrib
#!/bin/bash
set -e -u
export LANG="C"
export LC_COLLATE="C"
export LC_CTYPE="C"
export LC_MESSAGES="C"
export LC_MONETARY="C"
export LC_NUMERIC="C"
export LC_TIME="C"
export LC_ALL="C"
sed_cmd="sed -n 's/^author //p'"
function get_lines {
lines=$(git ls-tree --full-tree -r HEAD $DIR |
# grep -E '(.py|.js|.html)' |
cut -f 2 |
xargs -n1 git blame -w --line-porcelain |
eval "$1" |
sort -f |
uniq -ic |
sort -rn)
sum=0
while read -r line;
do
set -- junk $line
shift
count=$1
let sum+=count
done <<< "$lines"
percents=("")
while read -r line;
do
set -- junk $line
shift
count=$1
shift
name=$@
echo "$(printf %2d $count) ( $(printf %2.2f $(echo "scale = 2; $count * 100 / $sum" | bc))% ) $name"
done <<< "$lines"
}
DIR=${1-'./'}
get_lines "$sed_cmd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment