Estimate Code Size
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 | |
# Use this script like `./code_size.sh file1 file2 ... > output.txt` | |
set -eu; | |
function estimate() | |
{ | |
cat $1 | wc | |
# without comments and empty lines: | |
sed 's/#.*//' $1 \ | |
| sed '/^\s*$/d' \ | |
| wc | |
# Without the following tokens: | |
# - '\' at the end of a line. | |
# - '{{' (removed only if it's a template file) | |
# - '}}' or '-}}' (removed only if it's a template file) | |
# - '[ \t]+' replaced with a single space | |
# - trailing whitespaces | |
# as well as all the comments and empty lines removed. | |
case "$1" in | |
*template*) | |
sed 's/#.*//' $1 \ | |
| sed 's/\\$//' \ | |
| sed 's/{{//g' \ | |
| sed 's/-\?}}//g' \ | |
| sed 's/[ \t]\+/ /g' \ | |
| sed 's/\s\+$//g' \ | |
| sed '/^\s*$/d' \ | |
| wc | |
;; | |
*) | |
sed 's/#.*//' $1 \ | |
| sed 's/\\$//g' \ | |
| sed 's/[ \t]\+/ /g' \ | |
| sed 's/\s\+$//g' \ | |
| sed '/^\s*$/d' \ | |
| wc | |
;; | |
esac | |
} | |
for arg in $@ | |
do | |
estimate $arg | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should work on bash scripts, templated Dockerfiles (assuming filename contains 'template') and our Modusfiles.