#! /bin/sh
OS=`uname -s`
[[ $OS != 'Linux' ]] && [[ $OS != 'Darwin' ]] && { echo "Expected operating system (uname -s) of 'Linux' or 'Darwin', exiting"; exit; }
GIT_NAME=git
if [ $PWD = "$HOME" ]; then
GIT_NAME="/usr/bin/git --git-dir=$HOME/.rivendell/ --work-tree=$HOME"
fi
echo Enter name to search:;
read NAME;
echo "Enter number of weeks to search (integer > 0):";
read NUM_WEEKS;
COUNTER=0
if [ $OS = Linux ]; then
SUMMARY_START_PERIOD=`date -d "last sunday - $NUM_WEEKS weeks" '+%s'`
SUMMARY_END_PERIOD=`date -d "last sunday - $COUNTER weeks" '+%s'`
elif [ $OS = Darwin ]; then
SUMMARY_START_PERIOD=`date -v-sun -v-$NUM_WEEKS\w -v0H -v0M -v0S '+%s'`
SUMMARY_END_PERIOD=`date -v-sun -v-$COUNTER\w -v0H -v0M -v0S '+%s'`
fi
SUMMARY_STATISTICS=`$GIT_NAME log --author=$NAME --pretty=tformat: --numstat --since $SUMMARY_START_PERIOD --until $SUMMARY_END_PERIOD -p -- . ":(exclude)*lock.*" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "%s-%s=%s lines\n", add, subs, loc }'`
echo In $NUM_WEEKS weeks, $NAME contributed $SUMMARY_STATISTICS:
while [ $COUNTER -lt $NUM_WEEKS ]; do
let COUNTER_OFFSET=COUNTER+1
if [ $OS = Linux ]; then
START_WEEK=`date -d "last sunday - $COUNTER_OFFSET weeks" '+%s'`
END_WEEK=`date -d "last sunday - $COUNTER weeks" '+%s'`
START_WEEK_PRETTY=`date -d @$START_WEEK '+%Y-%m-%d'`
END_WEEK_PRETTY=`date -d @$END_WEEK '+%Y-%m-%d'`
elif [ $OS = Darwin ]; then
START_WEEK=`date -v-sun -v -$COUNTER_OFFSET\w -v0H -v0M -v0S '+%s'`
END_WEEK=`date -v-sun -v -$COUNTER\w -v0H -v0M -v0S '+%s'`
START_WEEK_PRETTY=`date -r $START_WEEK '+%Y-%m-%d'`
END_WEEK_PRETTY=`date -r $END_WEEK '+%Y-%m-%d'`
fi
DATE_RANGE_MESSAGE="From $START_WEEK_PRETTY to $END_WEEK_PRETTY:"
STATISTICS=`$GIT_NAME log --author=$NAME --pretty=tformat: --numstat --since $START_WEEK --until $END_WEEK -p -- . ":(exclude)*lock.*" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "%s-%s=%s lines\n", add, subs, loc }'`
echo $DATE_RANGE_MESSAGE $STATISTICS
let COUNTER=COUNTER+1
done
#Stories to complete:
#time increments of weeks, months, days, and hours are supported (in that order of preference)
#works on linux and mac
#Each read line prompts for a number of options and has defaults when empty or whitespace is the input.