Created
March 20, 2020 15:16
-
-
Save danielebarbaro/afcd35fab51e4f51b548379b2e1e4744 to your computer and use it in GitHub Desktop.
A scratch script to count commit days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Use: report.sh 2020 [email protected] | |
year=$1 | |
author=$2 | |
with_details=0 | |
git_options=" --oneline --first-parent --reverse --all --branches --date-order --abbrev-commit --date=local --date=short " | |
for directory in *; do | |
if [ -d "${directory}" ] && [ -d "${directory}/.git" ]; then | |
cd $directory | |
has_commit=0 | |
days="$(git log $git_options \ | |
--since={$year-01-01} \ | |
--until={$year-12-31} \ | |
--format="%h %cd %an %s" \ | |
--author="$author" | cut -d " " -f2-4 | uniq | sort | wc -l)" | |
if [ $days -gt 0 ]; | |
then | |
printf "\n\n* Find $days days in $directory:" | |
for month in {1..12} | |
do | |
working_days="$(ncal -m$month | grep -vE '^S|^ |^$' | sed 's/[[:alpha:]]//g' | fmt -w 1 | sort -n | wc -l | sed -e 's/^[[:space:]]*//')" | |
last_day_of_month="$(ncal -m$month | grep -vE '^S|^ |^$' | sed 's/[[:alpha:]]//g' | fmt -w 1 | sort -n | sed -e 's/^[[:space:]]*//' | tail -1)" | |
from_date="$(echo $year-$month-01 | sed -e 's/^[[:space:]]*//')" | |
until_date="$(echo $year-$month-$last_day_of_month | sed -e 's/^[[:space:]]*//')" | |
month_days="$(git log $git_options \ | |
--author=$author \ | |
--since=$from_date --until=$until_date \ | |
--pretty='format:%h %cd %an %s' | cut -d " " -f2-4 | uniq | sort | wc -l)" | |
if [ $month_days -gt 0 ]; | |
then | |
has_commit=1 | |
details="$(git log $git_options \ | |
--pretty='format:%ad %s' \ | |
--since=$from_date \ | |
--until=$until_date \ | |
--author=$author)" | |
printf "\nMonth $month: $month_days/$working_days days" | |
if [ with_details = 1 ]; then | |
printf "\n Details: \n$details" | |
fi | |
fi | |
done | |
if [ has_commit = 0 ]; then | |
printf "\nNeither a commit." | |
fi | |
printf "\n" | |
fi | |
cd .. | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment