-
Notifications
You must be signed in to change notification settings - Fork 4
/
git-authoract
executable file
·47 lines (40 loc) · 1.36 KB
/
git-authoract
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
#!/usr/bin/env bash
#=======================================================================
# git-authoract
# File ID: 6d9eb5a8-2526-11e4-be0d-c80aa9e67bbd
# [Description]
# License: GNU General Public License version 2 or later.
#=======================================================================
outfile=/tmp/git-authors.txt
git log --format="%ci %aN" "$@" | \
cut -c 1-7,26- | \
sort | \
uniq | \
cut -c -7 | \
uniq -c | \
rmspcall | \
perl -pe 's/^(\d+)\s(\S+)/$2 $1/' >$outfile
firstyear=$(head -1 $outfile | cut -f 1 -d -)
curryear=$(date +%Y)
for y in $(seq $firstyear $curryear); do
for m in $(seq -w 1 12); do
grep -q ^$y-$m $outfile || echo $y-$m 0 >>$outfile
done
done
sort $outfile >${outfile}.tmp
mv ${outfile}.tmp $outfile
headzero="$(cut -f 2 -d ' ' $outfile | uniq -c | rmspcall | head -1 | grep ' 0$')"
if test -n "$headzero"; then
numhead=$(echo $headzero | cut -f 1 -d ' ')
linecount=$(wc -l <$outfile)
tail -n -$[$linecount - $numhead] $outfile >${outfile}.tmp
mv ${outfile}.tmp $outfile
fi
tailzero="$(cut -f 2 -d ' ' $outfile | uniq -c | rmspcall | tail -1 | grep ' 0$')"
if test -n "$tailzero"; then
numtail=$(echo $tailzero | cut -f 1 -d ' ')
linecount=$(wc -l <$outfile)
head -n $[$linecount - $numtail] $outfile >${outfile}.tmp
mv ${outfile}.tmp $outfile
fi
stpl -f %Y-%m $outfile