Skip to content

Instantly share code, notes, and snippets.

@guidanoli
Last active March 8, 2022 15:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidanoli/3a3c93b2a18052d61c0080ea60120bfc to your computer and use it in GitHub Desktop.
Save guidanoli/3a3c93b2a18052d61c0080ea60120bfc to your computer and use it in GitHub Desktop.
Count directories by cases in git repository
#!/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"
@guidanoli
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment