Skip to content

Instantly share code, notes, and snippets.

@kika
Last active December 29, 2018 03:44
Show Gist options
  • Save kika/e5363fcf92c976ff3e3fb1d90d0bd5fc to your computer and use it in GitHub Desktop.
Save kika/e5363fcf92c976ff3e3fb1d90d0bd5fc to your computer and use it in GitHub Desktop.
Calculate daily progress in lines of code from git repo and generate csv file.
#!/bin/bash
DATE=gdate
set -euo pipefail
if [[ "${1:-}" == "" || "${2:-}" == "" ]]; then
echo "Usage: $0 <start date> <directory with source> [optional cloc args]"
exit 1
fi
TIME=$($DATE -d "$1" +%s)
DIR=$2
NOW=$($DATE +%s)
DAY=86400
PREV_STATS=""
while [[ $TIME < $NOW ]]; do
git checkout $(git rev-list -n 1 --before=$TIME --all) 2>/dev/null >/dev/null
STATS=$(cloc $DIR --json ${@:3} | jq -r '[.SUM.blank,.SUM.comment,.SUM.code,.SUM.nFiles]|map(tostring)|join(",")')
if [[ $STATS != $PREV_STATS ]]; then
echo "$($DATE -d @$TIME +%D),$STATS"
PREV_STATS=$STATS
fi
TIME=$(($TIME + $DAY))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment