Skip to content

Commit 348a60a

Browse files
committed
Simplify script
1 parent acc0a28 commit 348a60a

File tree

1 file changed

+11
-142
lines changed

1 file changed

+11
-142
lines changed

tools/git/scripts/lines_per_file

Lines changed: 11 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -8,156 +8,25 @@
88
#
99
# * Results should NOT be confused with source lines of code (SLOC). This implementation measures absolute file length.
1010

11+
# Determine root directory:
12+
root="$(git rev-parse --show-toplevel)"
13+
14+
# Define the path to a utility to annotate a file statistic stream:
15+
annotate_file_type="${root}/tools/git/scripts/annotate_file_type.awk"
16+
1117
# * `git ls-files`
1218
# - List indexed files.
1319
# * `xargs wc -l`
1420
# - Compute the number of lines within each file.
1521
# * `awk '{}'`
16-
# - Format output.
22+
# - Extract `count` and `filename` columns.
23+
# * `annotate_file_type`
24+
# - Prefix each result with a file type.
1725
git ls-files | xargs wc -l | awk '
18-
# Special cases...
1926
$2 ~ /^total$/ {
2027
next
2128
}
22-
/(LICENSE|NOTICE)$/ {
23-
print "LICENSE" OFS $1 OFS $2
24-
next
25-
}
26-
/datapackage\.json$/ {
27-
print "datapackage.json" OFS $1 OFS $2
28-
next
29-
}
30-
/package\.json$/ {
31-
print "package.json" OFS $1 OFS $2
32-
next
33-
}
34-
35-
# Known file extensions (keep in alphabetical order)...
36-
/\.awk$/ {
37-
print "AWK" OFS $1 OFS $2
38-
next
39-
}
40-
/\.bib$/ {
41-
print "BibTeX" OFS $1 OFS $2
42-
next
43-
}
44-
/\.c$/ {
45-
print "C" OFS $1 OFS $2
46-
next
47-
}
48-
/\.cpp$/ {
49-
print "C++" OFS $1 OFS $2
50-
next
51-
}
52-
/\.csl$/ {
53-
print "CSL" OFS $1 OFS $2
54-
next
55-
}
56-
/\.css$/ {
57-
print "CSS" OFS $1 OFS $2
58-
next
59-
}
60-
/\.csv$/ {
61-
print "CSV" OFS $1 OFS $2
62-
next
63-
}
64-
/\.eot$/ {
65-
print "fonts" OFS $1 OFS $2
66-
next
67-
}
68-
/\.gif$/ {
69-
print "gif" OFS $1 OFS $2
70-
next
71-
}
72-
/\.go$/ {
73-
print "Go" OFS $1 OFS $2
74-
next
75-
}
76-
/\.h$/ {
77-
print "C" OFS $1 OFS $2
78-
next
79-
}
80-
/\.hpp$/ {
81-
print "C++" OFS $1 OFS $2
82-
next
83-
}
84-
/\.html$/ {
85-
print "HTML" OFS $1 OFS $2
86-
next
87-
}
88-
/\.jl$/ {
89-
print "Julia" OFS $1 OFS $2
90-
next
91-
}
92-
/\.jpg$/ {
93-
print "JPG" OFS $1 OFS $2
94-
next
95-
}
96-
/\.js$/ {
97-
print "JavaScript" OFS $1 OFS $2
98-
next
99-
}
100-
/\.json$/ {
101-
print "JSON" OFS $1 OFS $2
102-
next
103-
}
104-
/Makefile$/ {
105-
print "make" OFS $1 OFS $2
106-
next
107-
}
108-
/\.md$/ {
109-
print "Markdown" OFS $1 OFS $2
110-
next
111-
}
112-
/\.mk$/ {
113-
print "make" OFS $1 OFS $2
114-
next
115-
}
116-
/\.png$/ {
117-
print "PNG" OFS $1 OFS $2
118-
next
119-
}
120-
/\.py$/ {
121-
print "Python" OFS $1 OFS $2
122-
next
123-
}
124-
/\.R$/ {
125-
print "R" OFS $1 OFS $2
126-
next
127-
}
128-
/\.sh$/ {
129-
print "bash" OFS $1 OFS $2
130-
next
131-
}
132-
/\.svg$/ {
133-
print "SVG" OFS $1 OFS $2
134-
next
135-
}
136-
/\.txt$/ {
137-
print "plaintext" OFS $1 OFS $2
138-
next
139-
}
140-
/\.woff$/ {
141-
print "fonts" OFS $1 OFS $2
142-
next
143-
}
144-
/\.yml$/ {
145-
print "YAML" OFS $1 OFS $2
146-
next
147-
}
148-
149-
# Special cases...
150-
$2 ~ /^\.([A-Za-z])+$|\/\.([A-Za-z])+$/ {
151-
print "dotfiles" OFS $1 OFS $2
152-
next
153-
}
154-
$2 ~ /\/([A-Za-z0-9_-])+$/ {
155-
print "executables" OFS $1 OFS $2
156-
next
157-
}
158-
159-
# Everything else...
16029
{
161-
print "OTHER" OFS $1 OFS $2
30+
print $1 OFS $2
16231
}
163-
'
32+
' | "${annotate_file_type}"

0 commit comments

Comments
 (0)