Skip to content

Instantly share code, notes, and snippets.

@cbrgm
Created December 7, 2023 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbrgm/825b2e479b08a96a1f8f50e4b6536278 to your computer and use it in GitHub Desktop.
Save cbrgm/825b2e479b08a96a1f8f50e4b6536278 to your computer and use it in GitHub Desktop.
git_path_analysis.sh
#!/bin/bash
# Usage: ./script_name.sh <depth> <output_limit> <pattern1> <pattern2> ...
# Example: ./script_name.sh 2 50 vendor .git tmp
# Validate and set depth
DEPTH=${1:-2}
if ! [[ "$DEPTH" =~ ^[0-9]+$ ]]; then
echo "Depth must be a positive integer."
exit 1
fi
shift
# Validate and set output limit
OUTPUT_LIMIT=${1:-50}
if ! [[ "$OUTPUT_LIMIT" =~ ^[0-9]+$ ]]; then
echo "Output limit must be a positive integer."
exit 1
fi
shift
# Build exclusion pattern
EXCLUDE_PATTERN=$(IFS='|'; echo "$*")
# Main command
git log --since="1 year ago" --pretty=format: --name-only | \
grep -Ev "$EXCLUDE_PATTERN" | \
awk -F'/' -v depth="$DEPTH" '{path=$1; for(i=2; i<=depth && i<=NF; i++) path=path"/"$i; print path}' | \
sort | uniq -c | sort -rg | head -n "$OUTPUT_LIMIT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment