Last active
March 8, 2023 15:39
-
-
Save lenaschimmel/bac310ac8269e40a18492c7c9cf7f7b4 to your computer and use it in GitHub Desktop.
Analyzes indentation in all files matching the find pattern in the given directory.
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
#!/usr/bin/env bash | |
set -e | |
if [ "$#" -ne 2 ] || ! [ -d "$1" ]; then | |
echo "Usage: $0 DIRECTORY PATTERN" >&2 | |
echo "Analyzes indentation in all files matching the find pattern in the given directory. Remember to quote your pattern." | |
exit 1 | |
fi | |
TARGETDIR=$(realpath $1) | |
TARGETDIR_NAME=$(basename "$TARGETDIR") | |
PATTERN=$2 | |
TMPFILE=${TMPDIR:-/tmp}/tmp_analyze_indent_$TARGETDIR_NAME | |
echo "" | |
echo "Analyzing indentation in project $TARGETDIR_NAME for files named '$PATTERN'..." | |
echo "" | |
find $TARGETDIR -name "$PATTERN" -exec cat {} > $TMPFILE \; | |
printf '%5s lines total\n' `cat $TMPFILE | wc -l` | |
echo "" | |
printf '%5s empty lines (not even whitespace)\n' `grep --count --no-filename -E "^$" $TMPFILE` | |
printf '%5s lines with only whitespace (no code)\n' `grep --count --no-filename -E "^\s+$" $TMPFILE` | |
printf '%5s lines with some whitespace before code\n' `grep --count --no-filename -E "^\s+\S" $TMPFILE` | |
printf '%5s lines with tabs before code\n' `grep --count --no-filename -E "^\t+\S" $TMPFILE` | |
printf '%5s lines with spaces before code\n' `grep --count --no-filename -E "^ +\S" $TMPFILE` | |
printf '%5s lines with tabs AND spaces before code\n' `grep --count --no-filename -E "^(\t+ +)|( +\t+)\S" $TMPFILE` | |
echo "" | |
printf '%5s lines with whitespace AFTER code\n' `grep --count --no-filename -E "\S( |\t)+$" $TMPFILE` | |
echo "" | |
for NUM in {1..20} | |
do | |
printf '%5s lines with %2s spaces before code\n' `grep --count --no-filename -E "^ {$NUM}\S" $TMPFILE` $NUM | |
done | |
echo "" | |
rm $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output will look like this: