-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext.sh
executable file
·84 lines (68 loc) · 1.88 KB
/
ext.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# Returns the number of types of programming languages
# which have been worked on since the last github sync.
# The script simply returns the number of unique file
# extensions which appear from the 'git status' command,
# where .h files and.c files are identified etc.
if [ -n "$1" ]; then
debug=1 # set to 1 for debugging info
else
debug=0
fi
# getting output of 'git status' command
changed=$(git status | grep ": ")
if [ $debug -eq "1" ]; then echo "$changed"; echo; fi
# filtering out everything which is not a file name
# with some extension
filtered=$( \
for item in $changed; \
do echo $item; \
done \
| grep -v "modified:" \
| grep -v "renamed:" \
| grep -v "^new$" \
| grep -v "^->$" \
| grep -v "file:" \
| grep -v 'deleted:' \
| grep -v '.out' \
| grep -v '.vim' \
| grep -v '.txt' \
| grep -v '.pdf' \
| grep -v '.so' \
| grep -v '.gdbinit' \
| grep -v '.vimrc' \
| grep -v '.dircolors' \
| grep -v '.mem' \
| grep -v '.yaml' \
| grep -v '.md' \
| grep -v '.gitignore' \
| grep '\.' \
)
if [ $debug -eq "1" ]; then echo "$filtered"; echo; fi
# keeping only file extensions, sorting and removing
# duplicates, with the following identifications:
# .h files are viewed as .c files
# .hpp files are viewed as .hpp files
# .y and .txt files are viewed as .l files
extensions=$( \
for item in $filtered; \
do echo ${item##*.}; \
done \
| sed 's/^h$/c/g' \
| sed 's/^hpp$/cpp/g' \
| sed 's/^y$/l/g' \
| sed 's/^ac$/m4/g' \
| sed 's/^am$/m4/g' \
| sed 's/^in$/m4/g' \
| sed 's/^jar$/java/g' \
| sed 's/^bin$/asm/g' \
| sort \
| uniq \
)
if [ $debug -eq "1" ]; then echo "$extensions"; echo; fi
# if not in debug mode then bring back 'git status' output
if [ ! $debug -eq "1" ]; then
git status
fi
# returning the number of file extensions left
echo "Total number of languages: $(echo "$extensions" | wc -l)"