Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions docs/lib/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

---
Expand All @@ -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
```

---
Expand All @@ -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
```

---
Expand Down
60 changes: 45 additions & 15 deletions lib/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,57 +187,87 @@ 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)

echo "Commits | Hour of day"
echo "--------+------------"
[[ -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("%7s | %-12s\n",$1,$2)}'
| awk '{printf("%11s | %6s\n",$2,$1)}'
}

## 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)

echo "Commits | Weekday (1=Monday)"
echo "--------+-------------------"
[[ -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("%7s | %-12s\n",$1,$2)}'
| awk '{printf("%18s | %6s\n",$2,$1)}'
}

## 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)

echo "Commits | Day of month"
echo "--------+-------------"
[[ -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("%7s | %-12s\n",$1,$2)}'
| awk '{printf("%12s | %6s\n",$2,$1)}'
}