Skip to content

Instantly share code, notes, and snippets.

@jugutier
Last active July 10, 2017 15:00
Show Gist options
  • Save jugutier/e4967eb52c0b88b9714c8833141bad81 to your computer and use it in GitHub Desktop.
Save jugutier/e4967eb52c0b88b9714c8833141bad81 to your computer and use it in GitHub Desktop.
code-distribution.sh
#!/bin/bash
function clean_up {
# Perform program exit housekeeping
echo -n "Cleanup? [y/n]: "
read
if [ "$REPLY" = "y" ]; then
echo "Cleaning...."
cd ..
rm -rf distribution
fi
kill $WEBSERVER_PID
exit
}
trap clean_up SIGHUP SIGINT SIGTERM
if [ ! -d ./distribution ] ; then
echo "Initializing graphic library..."
git clone https://gist.github.com/28e175c2a270a9131d8b91523705da1a.git distribution > /dev/null 2>&1
rm distribution/code-distribution.csv
echo "Project,File,Lines" > distribution/code-distribution.csv
else
echo "Library was ready"
fi
echo "Done! Browser will open next"
# Each of the following items explain what an individual piped command does.
# 1. Find Files that are relevant to an iOS project recursively from current directory. '-print0' is to handle folder names with spaces on it
# 2. Count lines for each of them. 'xargs -0' is to read folder names with spaces on it appropiately
# 3. Trim whitespace at the beginning of each line
# 4. Remove total count because there is no flag in 'wc' to disable it.
# 5. Remove everything after the first space (i.e path to file coming from wc's output)
# 6. Change to CSV format, hardcoded 1 for series number (increment and run again if you want to compare different code projects), Take advantage of line numbers in current to file id, The number of lines for that individual file.
find -E . -iregex ".*\.(h|m|c|cpp|mm|swift)" -print0 | xargs -0 wc -l | sed -e 's/^[ \t]*//' | sed \$d | cut -f1 -d" " | awk '{printf "1,%d,%s\n", NR, $0}' >> distribution/code-distribution.csv
cd distribution
python -m SimpleHTTPServer > /dev/null 2>&1 &
WEBSERVER_PID=$!
python -mwebbrowser http://localhost:8000 > /dev/null 2>&1
echo "This script will endlessly loop until you stop it (ctrl +c)"
while true; do
: # Do nothing
done
@jugutier
Copy link
Author

Calculate lines per file and output csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment