From e1e02024a1952241f0295f66619c51802d6e4baf Mon Sep 17 00:00:00 2001 From: arzzen Date: Sun, 8 Jun 2025 19:39:29 +0200 Subject: [PATCH 1/2] Activity calendar by author --- git-quick-stats | 68 +++++++++++++++++++++++++++++++++++++++++++++++ git-quick-stats.1 | 34 ++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/git-quick-stats b/git-quick-stats index a27ea9e..166b25e 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -72,6 +72,60 @@ fi # Set the legacy theme by typing "export _MENU_THEME=legacy" _theme="${_MENU_THEME:=default}" +# DESC: Shows a calendar heatmap of commits per day-of-week per month for a given author +# ARGS: $author (required) +function commitsCalendarByAuthor() { + local author="${1:-}" + [[ -z "$author" ]] && { echo "Usage: commitsCalendarByAuthor "; return 1; } + + optionPicked "Commit Activity Calendar for '$author'" + + # Print header + printf "\n Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n" + + # Map days to numbers for easier awk processing + local days=(Mon Tue Wed Thu Fri Sat Sun) + local months=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) + + # Gather commit counts + git -c log.showSignature=false log --use-mailmap $_merges \ + --date=iso --author="$author" "$_since" "$_until" $_log_options \ + --pretty='%ad' $_pathspec | awk ' + { + split($0, a, " "); + # a[1] = YYYY-MM-DD + split(a[1], date_fields, "-"); + mon = date_fields[2] + 0; + cmd = "date -d \"" a[1] "\" +%u"; + cmd | getline weekday; + close(cmd); + # weekday: 1=Mon, ..., 7=Sun + count[weekday][mon]++; + } + END { + # Output matrix + for (d=1; d<=7; d++) { + if (d==1) printf "Mon "; + else if (d==2) printf "Tue "; + else if (d==3) printf "Wed "; + else if (d==4) printf "Thu "; + else if (d==5) printf "Fri "; + else if (d==6) printf "Sat "; + else if (d==7) printf "Sun "; + for (m=1; m<=12; m++) { + c = count[d][m]+0; + if (c==0) out="..."; + else if (c<=9) out="░░░"; + else if (c<=19) out="▒▒▒"; + else out="▓▓▓"; + printf "%s%s", out, (m<12?" ":"\n"); + } + } + printf "\nLegend: ... = 0 ░░░ = 1–9 ▒▒▒ = 10–19 ▓▓▓ = 20+ commits\n"; + } + ' +} + ################################################################################ # HELPER AND MENU FUNCTIONS @@ -271,6 +325,8 @@ function showMenu() { printf %b "${NUMS} 21)${TEXT} Git commits per timezone by author\\n" printf %b "\\n${TITLES} Suggest:\\n" printf %b "${NUMS} 22)${TEXT} Code reviewers (based on git history)\\n" + printf %b "\\n${TITLES} Calendar:\\n" + printf %b "${NUMS} 23)${TEXT} Activity calendar by author\\n" printf %b "\\n${HELP_TXT}Please enter a menu option or ${EXIT_TXT}press Enter to exit.\\n" printf %b "${TEXT}> ${NORMAL}" read -r opt @@ -1116,6 +1172,13 @@ if [[ "$#" -eq 1 ]]; then read -r -p "Which author? " author done commitsByTimezone "${author}";; + # ACTIVITY OPTIONS + -k|--commits-calendar-by-author) + author="${_GIT_AUTHOR:-}" + while [[ -z "${author}" ]]; do + read -r -p "Which author? " author + done + commitsCalendarByAuthor "${author}";; # SUGGEST OPTIONS -r|--suggest-reviewers) suggestReviewers;; -h|-\?|--help) usage;; @@ -1202,6 +1265,11 @@ while [[ "${opt}" != "" ]]; do done commitsByTimezone "${author}"; showMenu;; 22) suggestReviewers; showMenu;; + 23) author="" + while [[ -z "${author}" ]]; do + read -r -p "Which author? " author + done + commitsCalendarByAuthor "${author}"; showMenu;; q|"\n") exit;; *) clear; optionPicked "Pick an option from the menu"; showMenu;; esac diff --git a/git-quick-stats.1 b/git-quick-stats.1 index f9ea257..6b1eb58 100644 --- a/git-quick-stats.1 +++ b/git-quick-stats.1 @@ -1,4 +1,4 @@ -.TH git-quick-stats "1" "April 2024" "git-quick-stats" "User Commands" +.TH git-quick-stats "1" "June 2025" "git-quick-stats" "User Commands" .SH NAME .B git\-quick\-stats \- Simple and efficient way to access various stats in a git repository. @@ -124,6 +124,11 @@ displays a list of commits per timezone .IP displays a list of commits per timezone by author .HP +.PP +\fB\-\-activity\-calendar\fR +.IP +displays a calendar-style grid of commit activity per day-of-week and month for a selected author. +.HP .SH SUGGEST OPTIONS .PP \fB\-r\fR, \fB\-\-suggest\-reviewers\fR @@ -167,5 +172,30 @@ You can switch to the legacy color scheme, example: You can set _GIT_BRANCH to set the branch of the stats, example: .PP .B export _GIT_BRANCH="master" -. +.PP +.SH CALENDAR ACTIVITY OUTPUT +.PP +\fBactivity-calendar\fR outputs a visual grid of commit activity for a selected author, grouped by day-of-week (rows: Mon..Sun) and month (columns: Jan..Dec). Each cell is 3 characters wide, separated by one space. +.PP +Sample output: +.PP +.nf + Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec +Mon ▓▓▓ ░░░ ▒▒▒ ░░░ ░░░ ▒▒▒ ▓▓▓ ░░░ ░░░ ▓▓▓ ▒▒▒ ▒▒▒ +Tue ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ▒▒▒ ░░░ ░░░ ░░░ +Wed ░░░ ▓▓▓ ░░░ ▓▓▓ ▒▒▒ ░░░ ░░░ ▒▒▒ ░░░ ░░░ ▓▓▓ ░░░ +Thu ░░░ ▒▒▒ ░░░ ░░░ ▒▒▒ ░░░ ▓▓▓ ▒▒▒ ▒▒▒ ░░░ ░░░ ▒▒▒ +Fri ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ░░░ ▓▓▓ ▒▒▒ ░░░ ▒▒▒ ░░░ ▒▒▒ ░░░ +Sat ░░░ ░░░ ▒▒▒ ░░░ ░░░ ░░░ ▒▒▒ ░░░ ▒▒▒ ▓▓▓ ▒▒▒ ░░░ +Sun ▓▓▓ ░░░ ▓▓▓ ░░░ ░░░ ▓▓▓ ░░░ ▒▒▒ ░░░ ░░░ ▓▓▓ ░░░ + +Legend: ... = 0 ░░░ = 1–2 ▒▒▒ = 3–5 ▓▓▓ = 6+ commits .fi + +.PP +.SH SEE ALSO +.BR git (1) +.PP +Project homepage: +.UR https://github.com/git-quick-stats/git-quick-stats +.UE \ No newline at end of file From d4f71cfdad2d9118165c5a84875b6137b4514cba Mon Sep 17 00:00:00 2001 From: arzzen Date: Sat, 14 Jun 2025 14:43:14 +0200 Subject: [PATCH 2/2] removed unuse arrays --- git-quick-stats | 4 ---- 1 file changed, 4 deletions(-) diff --git a/git-quick-stats b/git-quick-stats index 166b25e..b520501 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -83,10 +83,6 @@ function commitsCalendarByAuthor() { # Print header printf "\n Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n" - # Map days to numbers for easier awk processing - local days=(Mon Tue Wed Thu Fri Sat Sun) - local months=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) - # Gather commit counts git -c log.showSignature=false log --use-mailmap $_merges \ --date=iso --author="$author" "$_since" "$_until" $_log_options \