forked from garybernhardt/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-whodoneit
executable file
·47 lines (38 loc) · 892 Bytes
/
git-whodoneit
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
#!/usr/bin/env ruby
class WhoDoneIt
PATTERN = ARGV.fetch(0)
def print
lines.each do |line|
puts line
end
end
def lines
blame_and_code.map do |blame, code|
blame += " " * (longest_blame_line - blame.length)
"#{blame} #{code}"
end
end
def blame_and_code
@blame_and_code ||= blame_lines.map do |line|
blame, code = line.split(')', 2)
blame += ")"
[blame, code]
end
end
def longest_blame_line
@longest_blame_line ||= blame_and_code.map do |blame, code|
blame.length
end.max
end
def blame_lines
@blame_lines ||= matching_files.map do |filename|
`git blame -f -- #{filename} | grep #{PATTERN}`
end.map do |line|
line.split("\n")
end.flatten
end
def matching_files
@matching_files ||= `git grep -I --name-only #{PATTERN}`.split("\n")
end
end
WhoDoneIt.new.print