Viewing:
#! /usr/bin/env bash
gitdir="$1"
summed_commits="0"
echo -n "Commits (all YY):"
if [ "$gitdir" != "" ]; then
total_commits="$(git -C "$gitdir" rev-list --count HEAD)"
else
total_commits="$(git rev-list --count HEAD)"
fi
echo -n " all:$total_commits "
this_year=$(date +%Y)
twenty_years_ago=$(($this_year - 100))
for y in $(seq $this_year -1 $twenty_years_ago);
do
if [ "$total_commits" -eq "$summed_commits" ] ; then
break
fi
if [ "$gitdir" != "" ]; then
commits_in_year=$(git -C "$gitdir" rev-list --count HEAD --since $y-01-01 --until $(($y + 1))-01-01)
else
commits_in_year=$(git rev-list --count HEAD --since $y-01-01 --until $(($y + 1))-01-01)
fi
summed_commits=$(($summed_commits+$commits_in_year))
if [ "$commits_in_year" -gt "0" ]; then
echo -n "${y: -2}:$commits_in_year "
fi
done
echo