Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Last active July 3, 2020 10:27
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 shanecelis/6f91039a4e06303a69d74603b0db4cd2 to your computer and use it in GitHub Desktop.
Save shanecelis/6f91039a4e06303a69d74603b0db4cd2 to your computer and use it in GitHub Desktop.
Show a boxplot of lines of code per file on a logscale similar to a plot shown by Uncle Bob.
#!/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