Skip to content

Instantly share code, notes, and snippets.

@wibus-wee
Created December 1, 2024 03:28
Show Gist options
  • Save wibus-wee/1919a66a76621de6e515a738ca11f6c1 to your computer and use it in GitHub Desktop.
Save wibus-wee/1919a66a76621de6e515a738ca11f6c1 to your computer and use it in GitHub Desktop.
Git Contribution Stats
#!/bin/bash
# Define colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Check if author name is provided
if [ -z "$1" ]; then
echo "${RED}Please provide author name!${NC}"
echo "Usage: $0 <author name> [start date(YYYY-MM-DD)] [end date(YYYY-MM-DD)]"
exit 1
fi
AUTHOR=$1
START_DATE=$2
END_DATE=$3
# Build date parameters
DATE_PARAMS=""
if [ ! -z "$START_DATE" ]; then
DATE_PARAMS="$DATE_PARAMS --since=$START_DATE"
fi
if [ ! -z "$END_DATE" ]; then
DATE_PARAMS="$DATE_PARAMS --until=$END_DATE"
fi
echo "${PURPLE}==================== Git Contribution Stats ====================${NC}"
echo "${BLUE}Author: ${NC}$AUTHOR"
if [ ! -z "$START_DATE" ]; then
echo "${BLUE}Start Date: ${NC}$START_DATE"
fi
if [ ! -z "$END_DATE" ]; then
echo "${BLUE}End Date: ${NC}$END_DATE"
fi
echo "${PURPLE}=================================================${NC}\n"
# Count total commits
COMMIT_COUNT=$(git log --author="$AUTHOR" $DATE_PARAMS --oneline | wc -l)
echo "${YELLOW}Total Commits: ${NC}$COMMIT_COUNT"
# Count code changes
echo "\n${CYAN}Code Change Statistics:${NC}"
git log --author="$AUTHOR" $DATE_PARAMS --pretty=tformat: --numstat | awk '
{ add += $1; subs += $2; loc += $1 - $2 }
END {
printf "+ '${GREEN}'%s'${NC}'\n", add
printf "- '${RED}'%s'${NC}'\n", subs
printf "Net change: '${YELLOW}'%s'${NC}'\n", loc
}'
echo "\n${PURPLE}=================================================${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment