Skip to content

Commit 895e852

Browse files
committed
Add script to compute the number of bytes per file
1 parent f3a3662 commit 895e852

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

tools/git/scripts/bytes_per_file

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Prints the number of bytes in a file.
4+
#
5+
# <file_type> <number_of_bytes> <file_path>
6+
7+
# * `git ls-files`
8+
# - List indexed files.
9+
# * `ls -l`
10+
# - Print file info, which includes number of bytes.
11+
# * `awk '{}'`
12+
# - Format output.
13+
git ls-files | xargs ls -l | awk '
14+
# Special cases...
15+
/(LICENSE|NOTICE)$/ {
16+
print "LICENSE" OFS $5 OFS $9
17+
next
18+
}
19+
/datapackage\.json$/ {
20+
print "datapackage.json" OFS $5 OFS $9
21+
next
22+
}
23+
/package\.json$/ {
24+
print "package.json" OFS $5 OFS $9
25+
next
26+
}
27+
28+
# Known file extensions (keep in alphabetical order)...
29+
/\.awk$/ {
30+
print "AWK" OFS $5 OFS $9
31+
next
32+
}
33+
/\.bib$/ {
34+
print "BibTeX" OFS $5 OFS $9
35+
next
36+
}
37+
/\.c$/ {
38+
print "C" OFS $5 OFS $9
39+
next
40+
}
41+
/\.cpp$/ {
42+
print "C++" OFS $5 OFS $9
43+
next
44+
}
45+
/\.csl$/ {
46+
print "CSL" OFS $5 OFS $9
47+
next
48+
}
49+
/\.css$/ {
50+
print "CSS" OFS $5 OFS $9
51+
next
52+
}
53+
/\.csv$/ {
54+
print "CSV" OFS $5 OFS $9
55+
next
56+
}
57+
/\.eot$/ {
58+
print "fonts" OFS $5 OFS $9
59+
next
60+
}
61+
/\.gif$/ {
62+
print "gif" OFS $5 OFS $9
63+
next
64+
}
65+
/\.go$/ {
66+
print "Go" OFS $5 OFS $9
67+
next
68+
}
69+
/\.h$/ {
70+
print "C" OFS $5 OFS $9
71+
next
72+
}
73+
/\.hpp$/ {
74+
print "C++" OFS $5 OFS $9
75+
next
76+
}
77+
/\.html$/ {
78+
print "HTML" OFS $5 OFS $9
79+
next
80+
}
81+
/\.jl$/ {
82+
print "Julia" OFS $5 OFS $9
83+
next
84+
}
85+
/\.jpg$/ {
86+
print "JPG" OFS $5 OFS $9
87+
next
88+
}
89+
/\.js$/ {
90+
print "JavaScript" OFS $5 OFS $9
91+
next
92+
}
93+
/\.json$/ {
94+
print "JSON" OFS $5 OFS $9
95+
next
96+
}
97+
/Makefile$/ {
98+
print "make" OFS $5 OFS $9
99+
next
100+
}
101+
/\.md$/ {
102+
print "Markdown" OFS $5 OFS $9
103+
next
104+
}
105+
/\.mk$/ {
106+
print "make" OFS $5 OFS $9
107+
next
108+
}
109+
/\.png$/ {
110+
print "PNG" OFS $5 OFS $9
111+
next
112+
}
113+
/\.py$/ {
114+
print "Python" OFS $5 OFS $9
115+
next
116+
}
117+
/\.R$/ {
118+
print "R" OFS $5 OFS $9
119+
next
120+
}
121+
/\.sh$/ {
122+
print "bash" OFS $5 OFS $9
123+
next
124+
}
125+
/\.svg$/ {
126+
print "SVG" OFS $5 OFS $9
127+
next
128+
}
129+
/\.txt$/ {
130+
print "plaintext" OFS $5 OFS $9
131+
next
132+
}
133+
/\.woff$/ {
134+
print "fonts" OFS $5 OFS $9
135+
next
136+
}
137+
/\.yml$/ {
138+
print "YAML" OFS $5 OFS $9
139+
next
140+
}
141+
142+
# Special cases...
143+
$9 ~ /^\.([A-Za-z])+$|\/\.([A-Za-z])+$/ {
144+
print "dotfiles" OFS $5 OFS $9
145+
next
146+
}
147+
$9 ~ /\/([A-Za-z0-9_-])+$/ {
148+
print "executables" OFS $5 OFS $9
149+
next
150+
}
151+
152+
# Everything else...
153+
{
154+
print "OTHER" OFS $5 OFS $9
155+
}
156+
'

0 commit comments

Comments
 (0)