forked from d4rkd3v1l/uebersicht-git-stats.widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.sh
executable file
·47 lines (39 loc) · 1.48 KB
/
commands.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
#!/bin/sh
source "git-stats.widget/config.sh"
cd "$repoPath"
firstCommitTimeStamp=$(git log --pretty=%at | tail -1)
currentTimeStamp=$(date +%s)
totalDays=$(((currentTimeStamp-firstCommitTimeStamp)/86400))
function getRepoAge
{
if [ "$totalDays" -gt "365" ]; then
years=$((totalDays/365))
days=$((totalDays%365))
months=$((days/30))
age="$years years, $months months"
elif [ "$totalDays" -gt "30" ]; then
months=$(($totalDays/30))
days=$((totalDays%30))
age="$months months, $days days"
else
age="$totalDays days"
fi
echo $age
}
commitCount=$(git rev-list HEAD --count)
fileCount=$(git ls-files | wc -l)
if [ "$totalDays" -eq "0" ]; then
commitsPerDay=$commitCount
else
commitsPerDay=$commitCount/$totalDays
fi
results="{
\"repoName\":\"$(basename "$repoPath")\",
\"commitCount\":\"$commitCount\",
\"commitsPerDay\":\"$(echo "scale=2; $commitsPerDay" | bc | sed 's/^\./0./')\",
\"commitCountByDev\":\"<table>$(git shortlog -s -n HEAD | head -5 | tr '\t' ' ' | awk '{printf "<tr><td>%s. </td><td>%-2s %2s </td><td>%d </td><td>(%.2f%s)</td></tr>", NR,$2,$3,$1,$1/'"$commitCount"'*100,"%"}')</table>\",
\"repoAge\":\"$(getRepoAge)\",
\"fileCount\":\"$fileCount\",
\"fileCountByType\":\"<table>$(git ls-files | awk -F . '{print $NF}' | sort | uniq -c | sort -n -r | head -5 | awk '{printf "<tr><td>%s. </td><td>%s </td><td>%d </td><td>(%.2f%s)</td></tr>", NR,$2,$1,$1/'"$fileCount"'*100,"%"}')</table>\"
}"
echo "$results"