-
Notifications
You must be signed in to change notification settings - Fork 43
/
countLines.sh
executable file
·39 lines (34 loc) · 996 Bytes
/
countLines.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# A Unix shell script that displays the line count
# for each source code file recursively.
#
# The goal is to keep every file under 100 lines of code.
#
# By Curran Kelleher 4/15/2014
# $excluded is a regex for paths to exclude from line counting
excluded="spec\|node_modules\|bower_components\|README\|lib\|docs\|csv\|XLS\|json\|png\|\.git\|tsv"
countLines(){
# $total is the total lines of code counted
total=0
# -mindepth exclues the current directory (".")
for file in `find . -mindepth 1 -name "*.*" |grep -v "$excluded"`; do
# First sed: only count lines of code that are not commented with //
# Second sed: don't count blank lines
# $numLines is the lines of code
numLines=`cat $file | sed '/\/\//d' | sed '/^\s*$/d' | wc -l`
total=$(($total + $numLines))
echo " " $numLines $file
done
echo " " $total in total
}
echo Examples:
cd examples
countLines
cd ../
echo Unit tests:
cd tests
countLines
cd ../
echo Core files:
cd src
countLines
cd ../