Show a boxplot of lines of code per file on a logscale similar to a plot shown by Uncle Bob.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 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; | |
} | |
terminal="dumb"; | |
output=""; | |
name="$(pwd)"; | |
extension="cs"; | |
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;; | |
esac | |
done | |
shift $[ OPTIND - 1 ] | |
if [ $# -ne 1 ]; then | |
usage; | |
exit 2; | |
fi | |
dir="$1"; | |
(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 | |
$output | |
#set output "fileCount.png" | |
#set terminal dumb | |
plot '-' using (1.0):1 | |
EOF | |
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