Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Show a boxplot of lines of code per file on a logscale similar to a plot shown by Uncle Bob.
# boxplot-lines-of-code
# Written by Shane Celis
function usage() {
echo "usage: boxplot-lines-of-code [-h] [-e extension] [-p file.png] [-n name] <directory>" >&2;
echo " -e choose extension of files (\"cs\" by default)" >&2;
echo " -p output to png file instead of terminal" >&2;
echo " -n set plot label (present working directory by default)" >&2;
echo >&2;
echo "Show a boxplot of lines of code per file on a logscale similar to" >&2;
echo "a plot shown by Uncle Bob." >&2;
while getopts p:n:e:h opt; do
case $opt in
h) usage; exit 1;;
p) output="set output \"$OPTARG\""; terminal="png";;
n) name="$OPTARG";;
e) extension="$OPTARG";;
*) echo "error: invalid option given." >&2; usage;;
shift $[ OPTIND - 1 ]
if [ $# -ne 1 ]; then
exit 2;
(cat << EOF
set title "Lines of Code Per File"
set style fill solid 0.5 border -1
set style boxplot outliers pointtype 7
set style data boxplot
set boxwidth 0.5
set pointsize 0.5
unset key
set logscale y 10
set border 2
set xtics ("$name" 1, "B" 2) scale 0.0
set xtics nomirror
set ytics nomirror
set ylabel "lines of code"
# set yrange [0:100]
set terminal $terminal
#set output "fileCount.png"
#set terminal dumb
plot '-' using (1.0):1
find "$dir" -name "*.$extension" -print0 | xargs -0 -n 1 wc -l | awk '{ print $1 }') | gnuplot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment