From c4be0fe3c58fe07e235f624974b4f8102a17ecca Mon Sep 17 00:00:00 2001 From: 0scar Date: Wed, 21 Oct 2020 17:51:56 +0200 Subject: Add some neat scripts --- .scripts/commits_by_hour | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 .scripts/commits_by_hour (limited to '.scripts/commits_by_hour') diff --git a/.scripts/commits_by_hour b/.scripts/commits_by_hour new file mode 100755 index 0000000..1bfb293 --- /dev/null +++ b/.scripts/commits_by_hour @@ -0,0 +1,64 @@ +#!/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 -- cgit v1.3