Created
December 7, 2023 21:37
-
-
Save cbrgm/825b2e479b08a96a1f8f50e4b6536278 to your computer and use it in GitHub Desktop.
git_path_analysis.sh
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 | |
# 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