From 4d8534f5ac6b7e825d36895cdeb439b3c3ac025e Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 16 Oct 2023 22:43:10 +0200 Subject: [PATCH 1/2] lib/git: ggit-stat change columns order --- lib/git.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/git.sh b/lib/git.sh index ad3d076..ae9708a 100644 --- a/lib/git.sh +++ b/lib/git.sh @@ -192,8 +192,8 @@ ggit-stat-daily() { local user user=$(git config --get --global user.name) - echo "Commits | Hour of day" - echo "--------+------------" + echo "Hour of day | Commits" + echo "------------+--------" # shellcheck disable=SC2312 git --no-pager log \ --author="${user}" \ @@ -201,7 +201,7 @@ ggit-stat-daily() { --date="format:%H" \ | sort \ | uniq -c \ - | awk '{printf("%7s | %-12s\n",$1,$2)}' + | awk '{printf("%11s | %6s\n",$2,$1)}' } ## Statistics @@ -211,8 +211,8 @@ ggit-stat-weekly() { local user user=$(git config --get --global user.name) - echo "Commits | Weekday (1=Monday)" - echo "--------+-------------------" + echo "Weekday (1=Monday) | Commits" + echo "-------------------+--------" # shellcheck disable=SC2312 git --no-pager log \ --author="${user}" \ @@ -220,7 +220,7 @@ ggit-stat-weekly() { --date="format:%u" \ | sort \ | uniq -c \ - | awk '{printf("%7s | %-12s\n",$1,$2)}' + | awk '{printf("%18s | %6s\n",$2,$1)}' } ## Statistics @@ -230,8 +230,8 @@ ggit-stat-monthly() { local user user=$(git config --get --global user.name) - echo "Commits | Day of month" - echo "--------+-------------" + echo "Day of month | Commits" + echo "-------------+--------" # shellcheck disable=SC2312 git --no-pager log \ --author="${user}" \ @@ -239,5 +239,5 @@ ggit-stat-monthly() { --date="format:%d" \ | sort \ | uniq -c \ - | awk '{printf("%7s | %-12s\n",$1,$2)}' + | awk '{printf("%12s | %6s\n",$2,$1)}' } From 43ebd608740c2fbc248076931072b815b1525e2f Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 16 Oct 2023 22:58:11 +0200 Subject: [PATCH 2/2] lib/git: ggit-stat support filtering commits by date --- docs/lib/git.md | 18 +++++++++++++++--- lib/git.sh | 42 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/docs/lib/git.md b/docs/lib/git.md index 2b1e973..7e8a9a4 100644 --- a/docs/lib/git.md +++ b/docs/lib/git.md @@ -138,7 +138,11 @@ Show commit statistics: number of commits grouped by hour of the day. **Usage** ``` -ggit-stat-daily +ggit-stat-daily [AFTER] [BEFORE] + +Params: +AFTER Only count commits after this date +BEFORE Only count commits before this date ``` --- @@ -150,7 +154,11 @@ Show commit statistics: number of commits grouped by day of the month. **Usage** ``` -ggit-stat-monthly +ggit-stat-monthly [AFTER] [BEFORE] + +Params: +AFTER Only count commits after this date +BEFORE Only count commits before this date ``` --- @@ -162,7 +170,11 @@ Show commit statistics: number of commits grouped by day of the week. **Usage** ``` -ggit-stat-weekly +ggit-stat-weekly [AFTER] [BEFORE] + +Params: +AFTER Only count commits after this date +BEFORE Only count commits before this date ``` --- diff --git a/lib/git.sh b/lib/git.sh index ae9708a..4bef73c 100644 --- a/lib/git.sh +++ b/lib/git.sh @@ -187,18 +187,28 @@ ggit-patch() { ## Statistics ## Daily commits -################ +## +## @param $1 Count commits after this date +## @param $2 Count commits before this date +############################################## ggit-stat-daily() { + local after="${1:-}" + local before="${2:-}" + local date_filter=() local user + user=$(git config --get --global user.name) + [[ -n "${after}" ]] && date_filter=(--after="${after}") + [[ -n "${before}" ]] && date_filter=("${date_filter[@]}" --before="${before}") + echo "Hour of day | Commits" echo "------------+--------" # shellcheck disable=SC2312 git --no-pager log \ --author="${user}" \ --format=%ad \ - --date="format:%H" \ + --date="format:%H" "${date_filter[@]}" \ | sort \ | uniq -c \ | awk '{printf("%11s | %6s\n",$2,$1)}' @@ -206,18 +216,28 @@ ggit-stat-daily() { ## Statistics ## Weekly commits -################# +## +## @param $1 Count commits after this date +## @param $2 Count commits before this date +############################################## ggit-stat-weekly() { + local after="${1:-}" + local before="${2:-}" + local date_filter=() local user + user=$(git config --get --global user.name) + [[ -n "${after}" ]] && date_filter=(--after="${after}") + [[ -n "${before}" ]] && date_filter=("${date_filter[@]}" --before="${before}") + echo "Weekday (1=Monday) | Commits" echo "-------------------+--------" # shellcheck disable=SC2312 git --no-pager log \ --author="${user}" \ --format=%ad \ - --date="format:%u" \ + --date="format:%u" "${date_filter[@]}" \ | sort \ | uniq -c \ | awk '{printf("%18s | %6s\n",$2,$1)}' @@ -225,18 +245,28 @@ ggit-stat-weekly() { ## Statistics ## Monthly commits -################## +## +## @param $1 Count commits after this date +## @param $2 Count commits before this date +############################################## ggit-stat-monthly() { + local after="${1:-}" + local before="${2:-}" + local date_filter=() local user + user=$(git config --get --global user.name) + [[ -n "${after}" ]] && date_filter=(--after="${after}") + [[ -n "${before}" ]] && date_filter=("${date_filter[@]}" --before="${before}") + echo "Day of month | Commits" echo "-------------+--------" # shellcheck disable=SC2312 git --no-pager log \ --author="${user}" \ --format=%ad \ - --date="format:%d" \ + --date="format:%d" "${date_filter[@]}" \ | sort \ | uniq -c \ | awk '{printf("%12s | %6s\n",$2,$1)}'