#!/usr/bin/env bash VERBOSE=0 NO_HOUR=0 P='.' POSITIONAL=() while [[ $# -gt 0 ]]; do key="$1" case $key in -v|--verbose) VERBOSE=1 shift ;; -n|--no-hour) NO_HOUR=1 shift ;; -h|--help) echo "Usage: commits_by_hour [-v] [-n] [path]" echo " -v,--verbose Be more verbose, print all hours" echo " -n,--no-hour Don\'t print hours" echo " -h,--help Show this help message" echo " path Path to git repository (Default: .)" exit 0 ;; *) P=$1 shift ;; esac done cd $P # Writes number of commits categorized by hour of the day LOG=$(git log --format="%ad" | \ sed -Ee 's/.*([0-9]{2})(:[0-9]{2}){2}.*/\1/g' | \ sort | \ uniq -c | \ sed -Ee 's/^ +([0-9]+) ([0-9]+)/\2 \1/g') HOURS=({00..23}) for h in ${HOURS[*]}; do l=$(echo "$LOG" | grep -Eo "^$h [0-9]+") RES=$? if [ $RES -gt 0 ]; then # No commits in this hour if [ $VERBOSE -gt 0 ]; then if [ $NO_HOUR -gt 0 ]; then echo 0 else echo $h 0 fi fi else if [ $NO_HOUR -gt 0 ]; then echo `echo $l | sed -E 's/^[0-9]{2} ([0-9]+)$/\1/g'` else echo $l fi fi done