diff --git a/git-quick-stats b/git-quick-stats index 39b8d29..b1ebbcc 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -80,6 +80,56 @@ 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" + + # 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 @@ -281,6 +331,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 @@ -1134,6 +1186,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;; @@ -1220,6 +1279,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 76a6ca5..34dfb51 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 @@ -168,8 +173,34 @@ 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 +.PP You can set _GIT_IGNORE_AUTHORS to filter out specific authors, example: .PP .B export _GIT_IGNORE_AUTHORS="(author@examle.com|username)" . .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