/
css-stats-ack.sh
101 lines (86 loc) · 2.57 KB
/
css-stats-ack.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
## credit: https://gist.github.com/pjkix/1265822
## v1.0.6
## this script will gernerate css stats
### example output
# CSS STATS
# ----------
# Floats: 132
# Headings: 107
# Margins: 432
# Paddings: 463
# Font-Sizes: 170
# Importants: 56
echo 'CSS STATS'
echo '========='
echo
echo 'General: '
echo '----------'
## number of files
echo -n "Number of CSS files: "
ack --css -f | wc -l
## number of lines
# ack --nogroup --css --passthru * | wc -l | xargs echo "Number of Lines of Code (LoC)"
## longest file
echo 'File Length (LoC):'
find . -iname "*.css" | xargs wc -l | sort -r
echo
echo 'File Size (KBytes)'
# find . -iname "*.css" | xargs ls -l | awk '{print $5 "\t" $9}' | sort -nr ## Bytes
# find . -iname "*.css" | xargs ls -l | awk '{printf("%.1fK\t", $5 / 1024); print "\t" $9}' | sort -nr ## KB
find . -iname "*.css" -print0 | xargs -0 du -hsc | sort -nr ## block size
# find . -iname "*.css" -print0 | du -hsc ## block size
# stat -f "%z Bytes" stats.sh ## actual file size in bytes
echo
echo 'Props: '
echo '----------'
## append search results
# echo -n "test:"
echo -n "Floats: "
ack --nogroup --css float | wc -l
echo -n "Headings: "
ack --nogroup --css h[1-6] | wc -l
echo -n "Margins: "
ack --nogroup --css margin | wc -l
echo -n "Margins 0: "
ack --nogroup --css --match="margin-?(top|right|bottom|left)?\s*:\s*0" | wc -l
echo -n "Paddings: "
ack --nogroup --css padding | wc -l
echo -n "Padding 0: "
ack --nogroup --css --match="padding-?(top|right|bottom|left)?\s*:\s*0" | wc -l
echo -n "Font-Sizes: "
ack --nogroup --css font-size | wc -l
echo -n "Importants: "
ack --nogroup --css important | wc -l
echo
## colors
echo 'Colors:'
echo '----------'
echo -n "Hex: "
ack --nogroup --css --match="#[0-9a-fA-F]{3,6}" -o -h | wc -l
echo -n "RGB(a): "
ack --nogroup --css --match="rgba?\w*\(.*\)" -o -h | wc -l
echo
### unique
echo 'Unique Colors:'
echo '----------'
echo -n 'Hex: '
ack --nogroup --css --match="#[0-9a-fA-F]{3,6}" -o -h | sort | uniq -i -c | wc -l
echo
ack --nogroup --css --match="#[0-9a-fA-F]{3,6}" -o -h | sort | uniq -i -c | sort -r
echo
echo -n 'RGB(a): '
ack --nogroup --css --match="rgba?\w*\(.*\)" -o -h | sort | uniq -i -c | wc -l
echo
ack --nogroup --css --match="rgba?\w*\(.*\)" -o -h | sort | uniq -i -c | sort -r
echo
## Images
echo "Images:"
echo '----------'
echo -n "URLs:"
ack --nogroup --css --match="url\w?\(.*\)" -o -h | wc -l
### unique urls
echo -n "Unique URLs:"
ack --nogroup --css --match="url\w?\(.*\)" -o -h | sort | uniq -i -c | wc -l
echo
ack --nogroup --css --match="url\w?\(.*\)" -o -h | sort | uniq -i -c | sort -r