-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-praise
executable file
·53 lines (48 loc) · 1.58 KB
/
git-praise
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
#!/usr/bin/env ruby
def pretty_print(format, hash, commit, line)
desc = format.
gsub(/%H/, hash).
gsub(/%h/, hash[0,8]).
gsub(/%an/, commit[:author]).
gsub(/%ae/, commit[:author_mail]).
gsub(/%ad/, commit[:author_time].strftime("%d. %b %Y")).
gsub(/%Cred/, "\033[31m").
gsub(/%Cgreen/, "\033[32m").
gsub(/%Cblue/, "\033[34m").
gsub(/%Creset/, "\033[0m")
puts desc + "\t" + line
end
path = ARGV[0]
format = "%Cred%h%Cblue (%ad) %Cgreen%an%Creset"
hash = ""
commits = {}
`git blame -p #{path}`.split("\n").each do |line|
if line =~ /^([0-9a-f]{39,40})\s.*/
hash = $1
commits[hash] = {} unless commits[hash]
elsif line =~ /^author (.+)/
commits[hash][:author] = $1.strip
elsif line =~ /^author-mail (.+)/
commits[hash][:author_mail] = $1.strip
elsif line =~ /^author-time (.+)/
commits[hash][:author_time] = Time.at($1.strip.to_i)
elsif line =~ /^author-tz (.+)/
commits[hash][:author_tz] = $1.strip
elsif line =~ /^committer (.+)/
commits[hash][:committer] = $1.strip
elsif line =~ /^committer-mail (.+)/
commits[hash][:committer_mail] = $1.strip
elsif line =~ /^committer-time (.+)/
commits[hash][:committer_time] = Time.at($1.strip.to_i)
elsif line =~ /^committer-tz (.+)/
commits[hash][:committer_tz] = $1.strip
elsif line =~ /^summary (.+)/
commits[hash][:summary] = $1.strip
elsif line =~ /^previous (.+)/
commits[hash][:previous] = $1.strip
elsif line =~ /^filename (.+)/
commits[hash][:filename] = $1.strip
elsif line =~ /^\t(.*)/
pretty_print(format, hash, commits[hash], $1)
end
end