Skip to content

Instantly share code, notes, and snippets.

@holman
Created June 16, 2025 21:36
Show Gist options
  • Save holman/0fa807b775ef530b7ba3f7701edd073d to your computer and use it in GitHub Desktop.
Save holman/0fa807b775ef530b7ba3f7701edd073d to your computer and use it in GitHub Desktop.
inthunter
#!/bin/bash
# Get the user's global git email
user_email=$(git config --global user.email)
if [ -z "$user_email" ]; then
echo "Could not find your global git user.email. Please set it with 'git config --global user.email \"[email protected]\"'"
exit 1
fi
tmpfile=$(mktemp)
process_repo() {
dir="$1"
email="$2"
cd "$dir" || exit
if [ -d .git ]; then
# Only look at commits by the specified email
git log --author="$email" --pretty=format:'%H|%an|%ae' |
awk -F'|' -v repo="$(basename "$PWD")" '
{
match($1, /^[0-9]+/)
plen = RLENGTH
if (plen > maxlen) {
maxlen = plen
maxsha = $1
maxauthor = $2
maxemail = $3
}
}
END {
if (maxlen > 0) {
print repo "|" maxauthor "|" maxemail "|" maxsha "|" maxlen
}
}
'
fi
}
export -f process_repo
find . -mindepth 1 -maxdepth 1 -type d | xargs -I{} -P 4 bash -c 'process_repo "$@"' _ {} "$user_email" > "$tmpfile"
awk -F'|' '
{
if ($5 > maxlen) {
maxlen = $5
bestrepo = $1
bestauthor = $2
bestemail = $3
bestsha = $4
}
}
END {
if (maxlen > 0) {
print "Repo: " bestrepo
print "Author: " bestauthor " <" bestemail ">"
print "SHA: " bestsha
print "Numeric prefix length: " maxlen
} else {
print "No integer SHAs found for your author/email."
}
}
' "$tmpfile"
rm "$tmpfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment