Skip to content

Instantly share code, notes, and snippets.

@codingchili
Created April 26, 2025 17:22
Show Gist options
  • Save codingchili/a2dfef8c4343948de450cff5881aae10 to your computer and use it in GitHub Desktop.
Save codingchili/a2dfef8c4343948de450cff5881aae10 to your computer and use it in GitHub Desktop.
finds unique email domains among contributors in given path (org attribution)
#!/bin/bash
# Colors
GREEN="\033[0;32m"
BLUE="\033[0;34m"
YELLOW="\033[1;33m"
RED="\033[0;31m"
RESET="\033[0m"
FILEPATH="$1"
OUTPUT_FILE="path.txt"
if [[ -z "$FILEPATH" ]]; then
echo -e "${RED}❌ Usage: $0 <path>${RESET}"
exit 1
fi
echo -e "${BLUE}📂 Using output file:${RESET} ${YELLOW}$OUTPUT_FILE${RESET}"
rm -f "$OUTPUT_FILE"
echo -e "${BLUE}🔍 Extracting commits from:${RESET} ${YELLOW}$FILEPATH${RESET}..."
# Spinner function
spin() {
local -a sp=("⠋" "⠙" "⠸" "⠴" "⠦" "⠇")
local i=0
while kill -0 "$1" 2>/dev/null; do
printf "\r${YELLOW}${sp[i]} Searching...${RESET}"
i=$(( (i + 1) % 6 ))
sleep 0.1
done
printf "\r${GREEN}✔️ Done extracting commits!${RESET}\n"
}
# Run git log in background
(git log --pretty=format:"%an <%ae>" -- "$FILEPATH" > "$OUTPUT_FILE") &
GIT_PID=$!
spin $GIT_PID
echo -e "${BLUE}🕵️ Finding unique email domains...${RESET}"
# Capture and output
DOMAINS=$(grep -oP '<\K[^>]+(?=>)' "$OUTPUT_FILE" | awk -F'@' '{print $2}' | sort | uniq)
if [[ -z "$DOMAINS" ]]; then
echo -e "${RED}⚠️ No domains found.${RESET}"
exit 1
fi
# Pretty output
echo -e "${GREEN}📜 Unique domains:${RESET}"
echo "$DOMAINS" | while read domain; do
echo -e " ${YELLOW}•${RESET} $domain"
done
echo -e "${GREEN}🏁 Finished!${RESET}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment