-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-badge.sh
executable file
·57 lines (51 loc) · 1.4 KB
/
generate-badge.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
#!/bin/bash
while getopts 'b:d:e:f:o:s:r:' opt; do
case "$opt" in
b)
Before="$OPTARG"
if [ "$Before" == '[]' ]; then Before="$(date +%F)"; else Before=$1; fi
;;
d)
Dir="$OPTARG"
;;
e)
Excld="$OPTARG"
;;
f)
Filename="$OPTARG"
;;
o)
OutDir="$OPTARG"
;;
s)
Since="$OPTARG"
;;
r)
Rounding="$OPTARG"
;;
:)
echo "Usage: $(basename "$0") [-b Before] [-d Dir] [-e Exclude] [-f Filename] [-o OutputDir] [-s Since]"
exit 1
;;
?)
echo "Usage: $(basename "$0") [-b Before] [-d Dir] [-e Exclude] [-f Filename] [-o OutputDir] [-s Since]"
exit 1
;;
esac
done
if [ "$Excld" != '[]' ]; then
IFS=$'\n' read -rd '' -a array <<< "$Excld"
for word in "${array[@]}"; do
Exclude="${Exclude} -e $word"
done
fi
Count=$(hoc -d "$Dir" ${Exclude:+${Exclude[@]}} -s "$Since" -b "$Before" -f "int")
echo "Hits of code: $Count"
if [ "$Rounding" == "K" ]; then Count="$(python -c "print(round($Count/1000, 1))")K"
elif [ "$Rounding" == "M" ]; then Count="$(python -c "print(round($Count/1000000, 1))")M"
elif [ "$Rounding" == "G" ]; then Count="$(python -c "print(round($Count/1000000000, 1))")G"
else Count=$(python -c "print(format($Count, ',d'))")
fi
echo "Hits of code: $Count"
mkdir -p "$OutDir"
anybadge -l "Hits of Code" -v "$Count" -f "$OutDir/$Filename" -o -c royalblue