Created
December 19, 2024 19:05
-
-
Save Adzz/a7c25fae80e184dc76dac7fec08d588d to your computer and use it in GitHub Desktop.
Your Year In Git
This file contains hidden or 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 | |
RED="\033[31m" | |
GREEN="\033[32m" | |
RESET="\033[0m" | |
MAGENTA="\033[35m" | |
CYAN="\033[36m" | |
YELLOW="\033[33m" | |
BLUE="\033[34m" | |
# Function to check if the current directory is a Git repository | |
is_git_repo() { | |
git rev-parse --is-inside-work-tree &>/dev/null | |
} | |
# Check if the script is run inside a Git repository | |
if ! is_git_repo; then | |
echo "Error: This script must be run inside a Git repository." | |
exit 1 | |
fi | |
# Check if an author name is provided as an argument | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <author_name>" | |
exit 1 | |
fi | |
AUTHOR=$1 | |
# Get the current year | |
CURRENT_YEAR=$(date +%Y) | |
# Get the hash of the author's first commit of the year | |
FIRST_COMMIT_HASH=$(git log --author="$AUTHOR" --since="$CURRENT_YEAR-01-01" --pretty=format:"%H" | tail -1) | |
# Get the hash of the author's most recent commit | |
LATEST_COMMIT_HASH=$(git log --author="$AUTHOR" --since="$CURRENT_YEAR-01-01" --pretty=format:"%H" | head -1) | |
echo -e "\nYour ${BLUE}$CURRENT_YEAR ${RED}Y${GREEN}e${MAGENTA}a${CYAN}r${YELLOW} i${RED}n ${GREEN}G${MAGENTA}i${CYAN}t${RESET} ππ\n" | |
# Count the number of local branches | |
branch_count=$(git branch | wc -l) | |
echo -e "${GREEN}You have ${RED}$branch_count${GREEN} local branches.${RESET}\n" | |
echo -e "Enough for a forest!" | |
echo -e "But can you see the woods for the trees...π\n" | |
# Get the latest commit details | |
latest_commit=$(git log --author="$AUTHOR" -1 --pretty=format:"%ar") | |
echo -e "Your latest commit was: ${RED}$latest_commit${RESET}π±" | |
echo -e "Get back to work!\n" | |
linesadded=$(git log --numstat --pretty="%H" --author="$AUTHOR" $FIRST_COMMIT_HASH..$LATEST_COMMIT_HASH | awk 'NF==3 {plus+=$1; minus+=$2} END {print plus}') | |
echo -e "You made ${GREEN} +$linesadded ${RESET} additions! π" | |
linesremoved=$(git log --numstat --pretty="%H" --author="$AUTHOR" $FIRST_COMMIT_HASH..$LATEST_COMMIT_HASH | awk 'NF==3 {plus+=$1; minus+=$2} END {print minus}') | |
echo -e "...And ${RED} -$linesremoved ${RESET} removals π" | |
echo -e "Truly proving time is a flat circle.\n" | |
# Count commits by the specified author | |
author_commit_count=$(git log --author="$AUTHOR" --since="$CURRENT_YEAR-01-01" --pretty=oneline | wc -l) | |
echo -e "You made ${YELLOW}$author_commit_count${RESET} commits." | |
echo -e "Whoever said you had commitment issues.\n" | |
leaderboard=$(git shortlog --summary --numbered --all --no-merges --since="$CURRENT_YEAR-01-01") | |
echo -e "And finally no year in review would be complete without arbitrarily ranking" | |
echo -e "individuals and ${RED}pitting you against each other${RESET}.\n" | |
echo -e "${MAGENTA}${CURRENT_YEAR}${RESET} the leaderboard:\n\n$leaderboard\n" | |
echo -e "I hope you think about what you have done.\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment