Last active
March 8, 2022 15:45
-
-
Save guidanoli/3a3c93b2a18052d61c0080ea60120bfc to your computer and use it in GitHub Desktop.
Count directories by cases in git repository
This file contains 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
#!/usr/bin/env bash | |
set -euo pipefail | |
[ $# -ge 1 ] || (echo "Expected URI for git clone" >&2 && exit 1) | |
repodir=`mktemp -d` | |
git clone -- "$1" "$repodir" | |
pushd "$repodir" >/dev/null | |
folders=`git ls-files | xargs -r -d '\n' -n1 dirname | sort | uniq | xargs -r -d '\n' -n1 basename` | |
popd >/dev/null | |
rm -rf "$repodir" | |
snake_case=`echo "$folders" | grep -- '_' | tee snake | wc -l` | |
printf "snake\t$snake_case\n" | |
kebab_case=`echo "$folders" | grep -- '-' | tee kebab | wc -l` | |
printf "kebab\t$kebab_case\n" | |
camel_case=`echo "$folders" | grep -E -- '^[a-z0-9]+([A-Z0-9][a-z0-9]+)+$' | tee camel | wc -l` | |
printf "camel\t$camel_case\n" | |
pascal_case=`echo "$folders" | grep -E -- '^([A-Z0-9][a-z0-9]+)+$' | tee pascal | wc -l` | |
printf "pascal\t$pascal_case\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./find-cases.sh <my-git-repository-uri>
This will print the number of folders it could find in snake, kebab, camel and pascal cases and create files with those names listing the folders so you can ignore certain folders if you want.