diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2021-06-10 08:05:06 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2021-06-10 08:05:06 +0000 |
| commit | 7ad685aa6bd77d76115132280ce323d7fc5aeeb0 (patch) | |
| tree | c605992dfb5582a050b8847eb624fa84f1f97d91 /.local/bin/commits_by_hour | |
| parent | 6e4a15d79352ca2707a3b0d81d158228a7d14704 (diff) | |
Add scripts
Diffstat (limited to '.local/bin/commits_by_hour')
| -rwxr-xr-x | .local/bin/commits_by_hour | 64 |
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 |
