Skip to content

Instantly share code, notes, and snippets.

@jclosure
Last active January 19, 2023 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jclosure/b1c613cfa4beae3de9f3e93cd188e77d to your computer and use it in GitHub Desktop.
Save jclosure/b1c613cfa4beae3de9f3e93cd188e77d to your computer and use it in GitHub Desktop.
Count the commits and lines modified by a user, from a start date, across a bunch of projects.
#!/bin/bash
## usage: just run script (relative file paths to project adjusted)
# $ count_commits.sh
## array of project dirs
declare -a project_dirs=("./foo" "./bar" "./qux")
# ignore files with these extensions
excludes="':!*.ipynb' ':!*.json' ':!*.log' ':!*.pb' ':!*.fb' ':!*.bin'"
# begin on this date
start_date="01 Jan 2022"
## lib fns
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
## now loop through the above projects
for i in "${project_dirs[@]}"
do
echo -e "------ project: $i -------"
cd "$i"
user_name=$(git config user.name)
echo -e "commits:"
trim $(git --no-pager shortlog -s -n --all --since="$start_date" --author="$user_name" -- . $excludes)
echo -e ""
echo -e "lines:"
git log --numstat --pretty="%H" --author="$user_name" --since="$start_date" -- . $excludes \
| awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment