-
Notifications
You must be signed in to change notification settings - Fork 0
/
lines
executable file
·55 lines (53 loc) · 2.29 KB
/
lines
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
#
# lines: A lightweight but useful line calculator.
# Copyright (C) 2017 Travor Liu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
LINES_DIR=.
if [ -z "$1" ]
then
echo "No arguments given, counting lines of code in current directory"
else
echo "Counting lines of code in $1"
LINES_DIR=$1
fi
if [ ! -d "$LINES_DIR" ]
then
echo "error: \`$LINES_DIR': No such file or directory!"
else
C_LINES=`(find $LINES_DIR -regex '.*[.][ch]' -print0 | xargs -0 cat ) | wc -l`
echo "$C_LINES lines of C code"
ASM_LINES=`(find $LINES_DIR -name '*.asm' -print0 | xargs -0 cat) | wc -l`
echo "$ASM_LINES of Non-AT&T Assembly code"
GAS_LINES=`(find $LINES_DIR -regex '.*[.][Ss]' -print0 | xargs -0 cat) | wc -l`
echo "$GAS_LINES of AT&T Assembly code"
MK_LINES=`(find $LINES_DIR -name '*Makefile' -print0 | xargs -0 cat) | wc -l`
echo "$MK_LINES of Makefile code"
SH_LINES=`(find $LINES_DIR -name '*.sh' -print0 | xargs -0 cat) | wc -l`
echo "$SH_LINES of Shell script code"
HTML_LINES=`(find $LINES_DIR -name '*.html' -print0 | xargs -0 cat) | wc -l`
HTM_LINES=`(find $LINES_DIR -name '*.htm' -print0 | xargs -0 cat) | wc -l`
HTML_LINES=$(($HTML_LINES+$HTM_LINES))
echo "$HTML_LINES of HTML code"
JS_LINES=`(find $LINES_DIR -name '*.js' -print0 | xargs -0 cat) | wc -l`
echo "$JS_LINES of JavaScript code"
CSS_LINES=`(find $LINES_DIR -name '*.css' -print0 | xargs -0 cat) | wc -l`
echo "$CSS_LINES of CSS code"
PYTHON_LINES=`(find $LINES_DIR -name '*.py' -print0 | xargs -0 cat) | wc -l`
echo "$PYTHON_LINES of Python code"
TEX_LINES=`(find $LINES_DIR -name '*.tex' -print0 | xargs -0 cat) | wc -l`
echo "$TEX_LINES of LaTeX code"
echo "Total $(($C_LINES+$ASM_LINES+$MK_LINES+$GAS_LINES+$SH_LINES+$HTML_LINES+$JS_LINES+$CSS_LINES+$PYTHON_LINES+$TEX_LINES))"
fi