#! /bin/sh set -e root="$1" typ="$2" case "$typ" in 'commits') ;; 'changes') ;; '') typ='commits';; *) echo "Usage: $0 DIRECTORY [commits|changes]" >&2 exit 1 esac find "$root" -type d -name '.git' \ | while read -r dir do cd "$dir" || exit 1 git log --format=%ci --numstat done \ | gawk ' /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} / { date = $1 split(date, d, "-") year = d[1] commits[year]++ } /^[0-9]+\s+[0-9]+\s+/ { additions = $1 deletions = $2 changes[year] += additions + deletions } END { for (year in changes) { print year, "commits", commits[year] print year, "changes", changes[year] } }' \ | awk -v type_selected="$typ" ' { year = $1 type = $2 value = $3 d[year, type] = value if (value > max[type]) max[type] = value } END { for (yeartype in d) { split(yeartype, yt, SUBSEP) year = yt[1] type = yt[2] value = d[yeartype] if (type == type_selected) { printf "%s ", year for (i = 1; i <= (value * 100) / max[type]; i++) { printf "|" } printf "\n" } } }' \ | sort -n -k 1