Skip to content

Commit e70e3eb

Browse files
committed
Simplify script
1 parent 405139b commit e70e3eb

1 file changed

Lines changed: 16 additions & 189 deletions

File tree

tools/git/scripts/lines_per_file_type

Lines changed: 16 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -9,202 +9,29 @@
99
# * Results should NOT be confused with source lines of code (SLOC). This implementation measures absolute file length.
1010
# * `README.md` files are included in Markdown statistics.
1111

12-
# * `git ls-files`
13-
# - List indexed files.
14-
# * `xargs wc -l`
12+
# Determine root directory:
13+
root="$(git rev-parse --show-toplevel)"
14+
15+
# Define the path to a utility to compute the number of lines per file:
16+
lines_per_file="${root}/tools/git/scripts/lines_per_file"
17+
18+
# * `lines_per_file`
1519
# - Compute the number of lines within each file.
1620
# * `awk '{}'`
1721
# - Compute statistics.
1822
# * `sort -nr`
1923
# - Sort in reverse numeric order.
20-
git ls-files | xargs wc -l | awk '
21-
{
22-
N["total"] += 1
23-
}
24-
25-
# Special cases...
26-
$2 ~ /^total$/ {
27-
lines["total"] += $1
28-
next
29-
}
30-
/(LICENSE|NOTICE)$/ {
31-
lines["LICENSE"] += $1
32-
N["LICENSE"] += 1
33-
next
34-
}
35-
/datapackage\.json$/ {
36-
lines["datapackage.json"] += $1
37-
N["datapackage.json"] += 1
38-
next
39-
}
40-
/package\.json$/ {
41-
lines["package.json"] += $1
42-
N["package.json"] += 1
43-
next
44-
}
45-
46-
# Known file extensions (keep in alphabetical order)...
47-
/\.awk$/ {
48-
lines["AWK"] += $1
49-
N["AWK"] += 1
50-
next
51-
}
52-
/\.bib$/ {
53-
lines["BibTeX"] += $1
54-
N["BibTeX"] += 1
55-
next
56-
}
57-
/\.c$/ {
58-
lines["C"] += $1
59-
N["C"] += 1
60-
next
61-
}
62-
/\.cpp$/ {
63-
lines["C++"] += $1
64-
N["C++"] += 1
65-
next
66-
}
67-
/\.csl$/ {
68-
lines["CSL"] += $1
69-
N["CSL"] += 1
70-
next
71-
}
72-
/\.css$/ {
73-
lines["CSS"] += $1
74-
N["CSS"] += 1
75-
next
76-
}
77-
/\.csv$/ {
78-
lines["CSV"] += $1
79-
N["CSV"] += 1
80-
next
81-
}
82-
/\.eot$/ {
83-
lines["fonts"] += $1
84-
N["fonts"] += 1
85-
next
86-
}
87-
/\.gif$/ {
88-
lines["gif"] += $1
89-
N["gif"] += 1
90-
next
91-
}
92-
/\.go$/ {
93-
lines["Go"] += $1
94-
N["Go"] += 1
95-
next
96-
}
97-
/\.h$/ {
98-
lines["C"] += $1
99-
N["C"] += 1
100-
next
101-
}
102-
/\.hpp$/ {
103-
lines["C++"] += $1
104-
N["C++"] += 1
105-
next
106-
}
107-
/\.html$/ {
108-
lines["HTML"] += $1
109-
N["HTML"] += 1
110-
next
24+
"${lines_per_file}" | awk '
25+
$3 ~ /README\.md$/ {
26+
lines["README"] += $2
27+
N["README"] += 1
11128
}
112-
/\.jl$/ {
113-
lines["Julia"] += $1
114-
N["Julia"] += 1
115-
next
116-
}
117-
/\.jpg$/ {
118-
lines["JPG"] += $1
119-
N["JPG"] += 1
120-
next
121-
}
122-
/\.js$/ {
123-
lines["JavaScript"] += $1
124-
N["JavaScript"] += 1
125-
next
126-
}
127-
/\.json$/ {
128-
lines["JSON"] += $1
129-
N["JSON"] += 1
130-
next
131-
}
132-
/Makefile$/ {
133-
lines["make"] += $1
134-
N["make"] += 1
135-
next
136-
}
137-
/\.md$/ {
138-
if ($2 ~/README\.md$/) {
139-
lines["README"] += $1
140-
N["README"] += 1
141-
}
142-
lines["Markdown"] += $1
143-
N["Markdown"] += 1
144-
next
145-
}
146-
/\.mk$/ {
147-
lines["make"] += $1
148-
N["make"] += 1
149-
next
150-
}
151-
/\.png$/ {
152-
lines["PNG"] += $1
153-
N["PNG"] += 1
154-
next
155-
}
156-
/\.py$/ {
157-
lines["Python"] += $1
158-
N["Python"] += 1
159-
next
160-
}
161-
/\.R$/ {
162-
lines["R"] += $1
163-
N["R"] += 1
164-
next
165-
}
166-
/\.sh$/ {
167-
lines["bash"] += $1
168-
N["bash"] += 1
169-
next
170-
}
171-
/\.svg$/ {
172-
lines["SVG"] += $1
173-
N["SVG"] += 1
174-
next
175-
}
176-
/\.txt$/ {
177-
lines["plaintext"] += $1
178-
N["plaintext"] += 1
179-
next
180-
}
181-
/\.woff$/ {
182-
lines["fonts"] += $1
183-
N["fonts"] += 1
184-
next
185-
}
186-
/\.yml$/ {
187-
lines["YAML"] += $1
188-
N["YAML"] += 1
189-
next
190-
}
191-
192-
# Special cases...
193-
$2 ~ /^\.([A-Za-z])+$|\/\.([A-Za-z])+$/ {
194-
lines["dotfiles"] += $1
195-
N["dotfiles"] += 1
196-
next
197-
}
198-
$2 ~ /\/([A-Za-z0-9_-])+$/ {
199-
lines["executables"] += $1
200-
N["executables"] += 1
201-
next
202-
}
203-
204-
# Everything else...
20529
{
206-
lines["other"] += $1
207-
N["other"] += 1
30+
lines[$1] += $2
31+
N[$1] += 1
32+
33+
lines["total"] += $2
34+
N["total"] += 1
20835
}
20936
21037
END {

0 commit comments

Comments
 (0)