|
| 1 | +#!/bin/bash |
| 2 | +# .env File Gatekeeper - Because developers are sneaky little hobbitses |
| 3 | + |
| 4 | +# Colors for our dramatic warnings |
| 5 | +RED='\033[0;31m' |
| 6 | +GREEN='\033[0;32m' |
| 7 | +YELLOW='\033[1;33m' |
| 8 | +NC='\033[0m' # No Color |
| 9 | + |
| 10 | +# The forbidden patterns - we know your tricks! |
| 11 | +FORBIDDEN_PATTERNS=(".env*" "*.env" "env.*" "secrets.*" "config.*") |
| 12 | + |
| 13 | +# Check if we're in a git repo (because why else would you run this?) |
| 14 | +if ! git rev-parse --git-dir > /dev/null 2>&1; then |
| 15 | + echo -e "${RED}Not in a git repository. Are you lost?${NC}" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Look for sneaky files |
| 20 | +FOUND_FILES=() |
| 21 | +for pattern in "${FORBIDDEN_PATTERNS[@]}"; do |
| 22 | + while IFS= read -r -d '' file; do |
| 23 | + # Skip .gitignore because we're not monsters |
| 24 | + if [[ "$file" != *".gitignore" ]]; then |
| 25 | + FOUND_FILES+=("$file") |
| 26 | + fi |
| 27 | + done < <(find . -name "$pattern" -type f -print0 2>/dev/null) |
| 28 | +done |
| 29 | + |
| 30 | +# The moment of truth |
| 31 | +if [ ${#FOUND_FILES[@]} -eq 0 ]; then |
| 32 | + echo -e "${GREEN}✓ No forbidden files found. You're a good developer!${NC}" |
| 33 | + exit 0 |
| 34 | +fi |
| 35 | + |
| 36 | +# Oh dear... |
| 37 | +echo -e "${RED}⚠ DANGER WILL ROBINSON! Found forbidden files:${NC}" |
| 38 | +for file in "${FOUND_FILES[@]}"; do |
| 39 | + echo -e "${YELLOW} • $file${NC}" |
| 40 | + # Check if it's in .gitignore (common rookie mistake) |
| 41 | + if grep -q "$(basename "$file")" .gitignore 2>/dev/null; then |
| 42 | + echo -e " ${RED}But wait... it's in .gitignore! Classic misdirection.${NC}" |
| 43 | + fi |
| 44 | + # Check if it's already tracked (oh no) |
| 45 | + if git ls-files --error-unmatch "$file" > /dev/null 2>&1; then |
| 46 | + echo -e " ${RED}AND IT'S ALREADY TRACKED! PANIC!${NC}" |
| 47 | + fi |
| 48 | +done |
| 49 | + |
| 50 | +echo -e " ${RED}🚫 These files should NOT be committed. Add them to .gitignore!${NC}" |
| 51 | +echo -e "${YELLOW}💡 Pro tip: Use .env.example for non-sensitive defaults${NC}" |
| 52 | +exit 1 |
0 commit comments