-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfair-codesize.sh
executable file
·49 lines (42 loc) · 1.13 KB
/
fair-codesize.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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