|
8 | 8 | # |
9 | 9 | # * Results should NOT be confused with source lines of code (SLOC). This implementation measures absolute file length. |
10 | 10 |
|
| 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 | + |
11 | 17 | # * `git ls-files` |
12 | 18 | # - List indexed files. |
13 | 19 | # * `xargs wc -l` |
14 | 20 | # - Compute the number of lines within each file. |
15 | 21 | # * `awk '{}'` |
16 | | -# - Format output. |
| 22 | +# - Extract `count` and `filename` columns. |
| 23 | +# * `annotate_file_type` |
| 24 | +# - Prefix each result with a file type. |
17 | 25 | git ls-files | xargs wc -l | awk ' |
18 | | -# Special cases... |
19 | 26 | $2 ~ /^total$/ { |
20 | 27 | next |
21 | 28 | } |
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... |
160 | 29 | { |
161 | | - print "OTHER" OFS $1 OFS $2 |
| 30 | + print $1 OFS $2 |
162 | 31 | } |
163 | | -' |
| 32 | +' | "${annotate_file_type}" |
0 commit comments