|
8 | 8 | # |
9 | 9 | # * Results should NOT be confused with source lines of code (SLOC). This implementation measures only the number of nonempty lines. |
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 grep -c -v '^$'` |
14 | 20 | # - Count the number of nonempty lines within each file. |
15 | 21 | # * `sed 's//\2 \1/'` |
16 | 22 | # - Split on the file name and count separator and reverse the arguments. |
17 | 23 | # * `awk '{}'` |
18 | | -# - Format output. |
19 | | -git ls-files | xargs grep -c -v '^$'| sed 's/\(.*\):\([0-9]\{1,\}\)/\2 \1/' | awk ' |
20 | | -# Special cases... |
21 | | -/(LICENSE|NOTICE)$/ { |
22 | | - print "LICENSE" OFS $1 OFS $2 |
23 | | - next |
24 | | -} |
25 | | -/datapackage\.json$/ { |
26 | | - print "datapackage.json" OFS $1 OFS $2 |
27 | | - next |
28 | | -} |
29 | | -/package\.json$/ { |
30 | | - print "package.json" OFS $1 OFS $2 |
31 | | - next |
32 | | -} |
33 | | -
|
34 | | -# Known file extensions (keep in alphabetical order)... |
35 | | -/\.awk$/ { |
36 | | - print "AWK" OFS $1 OFS $2 |
37 | | - next |
38 | | -} |
39 | | -/\.bib$/ { |
40 | | - print "BibTeX" OFS $1 OFS $2 |
41 | | - next |
42 | | -} |
43 | | -/\.c$/ { |
44 | | - print "C" OFS $1 OFS $2 |
45 | | - next |
46 | | -} |
47 | | -/\.cpp$/ { |
48 | | - print "C++" OFS $1 OFS $2 |
49 | | - next |
50 | | -} |
51 | | -/\.csl$/ { |
52 | | - print "CSL" OFS $1 OFS $2 |
53 | | - next |
54 | | -} |
55 | | -/\.css$/ { |
56 | | - print "CSS" OFS $1 OFS $2 |
57 | | - next |
58 | | -} |
59 | | -/\.csv$/ { |
60 | | - print "CSV" OFS $1 OFS $2 |
61 | | - next |
62 | | -} |
63 | | -/\.eot$/ { |
64 | | - print "fonts" OFS $1 OFS $2 |
65 | | - next |
66 | | -} |
67 | | -/\.gif$/ { |
68 | | - print "gif" OFS $1 OFS $2 |
69 | | - next |
70 | | -} |
71 | | -/\.go$/ { |
72 | | - print "Go" OFS $1 OFS $2 |
73 | | - next |
74 | | -} |
75 | | -/\.h$/ { |
76 | | - print "C" OFS $1 OFS $2 |
77 | | - next |
78 | | -} |
79 | | -/\.hpp$/ { |
80 | | - print "C++" OFS $1 OFS $2 |
81 | | - next |
82 | | -} |
83 | | -/\.html$/ { |
84 | | - print "HTML" OFS $1 OFS $2 |
85 | | - next |
86 | | -} |
87 | | -/\.jl$/ { |
88 | | - print "Julia" OFS $1 OFS $2 |
89 | | - next |
90 | | -} |
91 | | -/\.jpg$/ { |
92 | | - print "JPG" OFS $1 OFS $2 |
93 | | - next |
94 | | -} |
95 | | -/\.js$/ { |
96 | | - print "JavaScript" OFS $1 OFS $2 |
97 | | - next |
98 | | -} |
99 | | -/\.json$/ { |
100 | | - print "JSON" OFS $1 OFS $2 |
101 | | - next |
102 | | -} |
103 | | -/Makefile$/ { |
104 | | - print "make" OFS $1 OFS $2 |
105 | | - next |
106 | | -} |
107 | | -/\.md$/ { |
108 | | - print "Markdown" OFS $1 OFS $2 |
109 | | - next |
110 | | -} |
111 | | -/\.mk$/ { |
112 | | - print "make" OFS $1 OFS $2 |
113 | | - next |
114 | | -} |
115 | | -/\.png$/ { |
116 | | - print "PNG" OFS $1 OFS $2 |
117 | | - next |
118 | | -} |
119 | | -/\.py$/ { |
120 | | - print "Python" OFS $1 OFS $2 |
121 | | - next |
122 | | -} |
123 | | -/\.R$/ { |
124 | | - print "R" OFS $1 OFS $2 |
125 | | - next |
126 | | -} |
127 | | -/\.sh$/ { |
128 | | - print "bash" OFS $1 OFS $2 |
129 | | - next |
130 | | -} |
131 | | -/\.svg$/ { |
132 | | - print "SVG" OFS $1 OFS $2 |
133 | | - next |
134 | | -} |
135 | | -/\.txt$/ { |
136 | | - print "plaintext" OFS $1 OFS $2 |
137 | | - next |
138 | | -} |
139 | | -/\.woff$/ { |
140 | | - print "fonts" OFS $1 OFS $2 |
141 | | - next |
142 | | -} |
143 | | -/\.yml$/ { |
144 | | - print "YAML" OFS $1 OFS $2 |
145 | | - next |
146 | | -} |
147 | | -
|
148 | | -# Special cases... |
149 | | -$2 ~ /^\.([A-Za-z])+$|\/\.([A-Za-z])+$/ { |
150 | | - print "dotfiles" OFS $1 OFS $2 |
151 | | - next |
152 | | -} |
153 | | -$2 ~ /\/([A-Za-z0-9_-])+$/ { |
154 | | - print "executables" OFS $1 OFS $2 |
155 | | - next |
156 | | -} |
157 | | -
|
158 | | -# Everything else... |
159 | | -{ |
160 | | - print "OTHER" OFS $1 OFS $2 |
161 | | -} |
162 | | -' |
| 24 | +# - Extract `count` and `filename` columns. |
| 25 | +# * `annotate_file_type` |
| 26 | +# - Prefix each result with a file type. |
| 27 | +git ls-files | xargs grep -c -v '^$'| sed 's/\(.*\):\([0-9]\{1,\}\)/\2 \1/' | awk '{print $1 OFS $2}' | "${annotate_file_type}" |
0 commit comments