-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-stats
More file actions
executable file
·65 lines (60 loc) · 1.88 KB
/
Copy pathgit-stats
File metadata and controls
executable file
·65 lines (60 loc) · 1.88 KB
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
#!/usr/bin/env bash
if [ $# -ge 1 ];then
datestr=$1
else
datestr="lastweek";
fi;
if [ $# -ge 2 ];then
path=$2
else
path="";
fi;
if [ $datestr = "--help" ] || [ $datestr = "?" ] ;then
echo 'git stats [[-][number]|all|lastweek lastweek] [path .]';
exit;
fi;
sinceday=""
beforeday=""
valid=false
isNumber=`grep '^[-[:digit:]]*$' <<< "$datestr"`
if [ "$(uname)" == "Darwin" ]; then
if [ $datestr = "lastweek" ];then
beforeday="--before="`date -v -sat "+%Y-%m-%d"`
startTime=$[`date -v -sat "+%s"`- 7*86400]
sinceday="--since="`date -r $startTime "+%Y-%m-%d"`
valid=true
fi;
if [ "$isNumber" != "" ];then
valid=true
if [ "$datestr" -gt 0 ];then
sinceday="--since="`date -v -${datestr#-}d "+%Y-%m-%d"`
else
beforeday="--before="`date -v -${datestr#-}d "+%Y-%m-%d"`
fi;
fi;
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
if [ $datestr = "lastweek" ];then
beforeday="--before="`date -d "last Saturday" "+%Y-%m-%d"`
startTime=$[`date -d "last Saturday" "+%s"`- 7*86400]
sinceday="--since="`date -d @$startTime "+%Y-%m-%d"`
fi;
if [ "$isNumber" != "" ];then
if [ "$datestr" -gt 0 ];then
sinceday="--since="`date -d "-${datestr#-} days" "+%Y-%m-%d"`
else
beforeday="--before="`date -d "-${datestr#-} days" "+%Y-%m-%d"`
fi;
fi;
fi
if [ $datestr = "all" ];then
beforeday="";
sinceday="";
fi;
Authors=`git shortlog -sne | awk '{print $2}'`
if [ "$sinceday" != "" ] || [ "$beforeday" != "" ]; then
echo -e "\033[32mget stas " $sinceday $beforeday "\033[0m";
fi;
for author in ${Authors}
do
git log --author=$author --pretty=tformat: --numstat $sinceday $beforeday $path | awk '{ add += $1 ; subs += $2 ; loc += $1 + $2 } END { printf "'$author' %s+ %s- total lines: %s\n",add,subs,loc }'
done