Last active
July 10, 2017 15:00
-
-
Save jugutier/e4967eb52c0b88b9714c8833141bad81 to your computer and use it in GitHub Desktop.
code-distribution.sh
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Calculate lines per file and output csv