summaryrefslogtreecommitdiff
path: root/.local/bin/commits_by_hour
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/commits_by_hour')
-rwxr-xr-x.local/bin/commits_by_hour64
1 files changed, 64 insertions, 0 deletions
diff --git a/.local/bin/commits_by_hour b/.local/bin/commits_by_hour
new file mode 100755
index 0000000..1bfb293
--- /dev/null
+++ b/.local/bin/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