Skip to content

Instantly share code, notes, and snippets.

@andmarios
Last active October 3, 2015 21:12
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 andmarios/62237b22cad1ee88af16 to your computer and use it in GitHub Desktop.
Save andmarios/62237b22cad1ee88af16 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Marios Andreopoulos, 2015
# A very simple bash script that goes into a git directory, counts lines of code
# for a certain language and each commit and creates a plot.
# $1 is path to git repository, $2 is language name as supported by cloc (e.g Go, Bourne Shell)
# bash linesPerCommitPlot.sh my-repo Go
# NEVER run it in your work directory. Make a temporary clone and use it there.
CURRENT="$(pwd)"
echo "files,language,blank,comment,code" > lineCommit-stats.csv
pushd $1
for i in $(git rev-list --reverse HEAD); do
git checkout $i --
cloc --csv --include-lang=$2 --quiet . | tail -n1 >> "$CURRENT"/lineCommit-stats.csv
done
REPO="$(basename $(pwd))"
popd
cat <<EOF | gnuplot
set terminal pdf size 8, 5 color enh
set output "$REPO-lines-stats.pdf"
set datafile separator ","
set xlabel 'commit'
set ylabel 'lines (#)'
set y2label 'files (#)'
set title "$REPO — $2 lines per commit"
set grid ytics
show grid
set xrange [1:*]
show xrange
#set autoscale xmax xfixmin
set yrange [0:]
set ytics nomirror
set y2tics
set y2range [0:]
set style line 1 lt 1 lw 3 pt 7 pi 0 ps 0.6
set pointintervalbox 1.5
set key left top
set key invert
set boxwidth 0.5 relative
set style fill solid
plot 'lineCommit-stats.csv' u (\$0+1):1 ti col with boxes axes x1y2 lc rgb "#E0F8F7",\
'' u (\$0+1):3 ti col with linespoints ls 1 lc rgb "gray75",\
'' u (\$0+1):4 ti col with linespoints ls 1 lc rgb "#FE642E",\
'' u (\$0+1):5 ti col with linespoints ls 1 lc rgb "#74DF00"
EOF
rm -f lineCommit-stats.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment