CORE/count_characters.sh

53 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
if [ "$1" == "--help" ]; then
echo "Environment variables: VERBOSE (false)"
echo " FILEEXTENSION (*)"
echo " IGNORE_SCRIPT (false)"
echo " IGNORE_DOCUMENTATION (false)"
echo " NUMBER_ONLY (false)"
exit 0
fi
function dircount() {
if [ "$VERBOSE" == "true" ]; then echo ":: Checking directory \"$*\"..."; fi
cd "$*" || exit 54
for file in $FILEEXTENSION; do
export "file_full=$*/$file"
if [ -d "$file" ]; then
if [ "$file" == "devprj" ]; then
if [ "$VERBOSE" == "true" ]; then echo ":: Skipping directory \"devprj\"";fi
else
if [ "$IGNORE_DOCUMENTATION" == "true" ] && [ "$file" == "docs" ]; then
if [ "$VERBOSE" == "true" ]; then echo ":: Skipping directory \"docs\"";fi
else
dircount "$file_full"
fi
fi
elif [ -f "$file" ]; then
if [ "$IGNORE_SCRIPT" == "true" ] && [ "$file" == "count_characters.sh" ]; then
if [ "$VERBOSE" == "true" ]; then echo ":: Skipping this script"; fi
else
if [ "$VERBOSE" == "true" ]; then echo ":: Counting characters in file \"$file_full\"..."; fi
export "COUNT_FILE=$(wc -m < "$file_full")"
export "COUNT=$((COUNT + COUNT_FILE))"
fi
else
if [ "$VERBOSE" == "true" ]; then echo ":: Skipping \"$file_full\" (no file or directory)"; fi
fi
done
cd ..
}
if [ "$FILEEXTENSION" == "" ]; then
export "FILEEXTENSION=*"
fi
if [ "$*" == "" ]; then
dircount "$(pwd)"
else
dircount "$(pwd)/$*"
fi
if [ "$VERBOSE" == "true" ]; then echo ""; fi
if [ "$NUMBER_ONLY" == "true" ]; then
echo "$COUNT"
else
echo "Characters counted: $COUNT"
fi