Skip to content

Instantly share code, notes, and snippets.

@marcosinger
Created February 6, 2015 22:16
Show Gist options
  • Save marcosinger/109000c6ee7339055ec7 to your computer and use it in GitHub Desktop.
Save marcosinger/109000c6ee7339055ec7 to your computer and use it in GitHub Desktop.
A shell script to count how many lines of code in each language each author added/removed in a repo
#!/bin/bash
git status &>-
if [ "$?" -ne 0 ]; then
printf "%0s$(echo -en "\033[1;31m")Error :$(echo -en "\033[0m") Run this command in a git repo"
exit 1
fi
declare -A techs=( ["Ruby"]="rb" ["Javascript"]="js" ["Html"]="html" ["Css"]="css")
authors=$(git shortlog -s | awk '{print $2}')
for tech in "${!techs[@]}"; do
printf "%0s[ $(echo -en "\033[1;32m")$tech$(echo -en "\033[0m") ]\n"
read maxA maxR <<<$(git log --pretty=format: --numstat | grep -v vendor | grep -w ${techs["$tech"]} | awk '{ ADDED+= $1 } {REM+= $2 } END { print ADDED, REM}')
for at in ${authors[@]}; do
read a r <<<$(git log --author $at --pretty=format: --numstat | grep -v vendor | grep -w ${techs["$tech"]} | awk '{ ADDED+= $1 } { REM+= $2 } END { print ADDED, REM }')
if [ ! -z "$a" ] && [ "$maxA" -ne 0 ]; then
ap=$(echo "scale=2; $a / $maxA * 100" | bc)
fi
if [ ! -z "$r" ] && [ "$maxR" -ne 0 ]; then
rp=$(echo "scale=2; $r / $maxR * 100" | bc)
fi
if [ ! -z "$a" ]; then
printf "%3s[ $(echo -en "\033[1;36m")$at$(echo -en "\033[0m") ] ~> "
printf "$(echo -en "\033[1;32m")+++ $a$(echo -en "\033[0m") ($ap)"
fi
if [ ! -z "$r" ]; then
printf " | "
printf "$(echo -en "\033[1;31m")--- $r$(echo -en "\033[0m") ($rp)\n"
fi
done
printf "\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment