Skip to content

Instantly share code, notes, and snippets.

@mohamedawnallah
Last active September 23, 2025 01:14
Show Gist options
  • Select an option

  • Save mohamedawnallah/aee92795cc48ac43badca6e5108efcde to your computer and use it in GitHub Desktop.

Select an option

Save mohamedawnallah/aee92795cc48ac43badca6e5108efcde to your computer and use it in GitHub Desktop.
get_coauthor() {
local github_user="$1"
if [[ -z "$github_user" ]]; then
echo "Usage: get_coauthor <github_username>"
echo "Example: get_coauthor mohamedawnallah"
return 1
fi
# Normalize the input username.
local normalized_input=$(echo "$github_user" | tr -d ' ' | tr '[:upper:]' '[:lower:]')
# Try to find matching author by comparing normalized names
local result=$(git log --all --format="%ae|%an" | while IFS='|' read -r email name; do
# Normalize the git log name.
local normalized_name=$(echo "$name" | tr -d ' ' | tr '[:upper:]' '[:lower:]')
# Check if normalized names match.
if [[ "$normalized_name" == *"$normalized_input"* ]]; then
echo "$email|$name"
break
fi
done)
local email=""
local full_name=""
if [[ -n "$result" ]]; then
email=$(echo "$result" | cut -d'|' -f1)
full_name=$(echo "$result" | cut -d'|' -f2)
else
# Fallback to GitHub noreply email.
email="${github_user}@users.noreply.github.com"
full_name="$github_user"
fi
# Return the co-authored-by line.
echo "Co-authored-by: $full_name <$email>"
}
# CoAuthor gets the coauthor GitHub template for a given user id.
alias coauthor='get_coauthor'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment