Skip to content

Instantly share code, notes, and snippets.

@parkan
Created August 14, 2014 21:33
Show Gist options
  • Save parkan/5b95929f58b0b2bae860 to your computer and use it in GitHub Desktop.
Save parkan/5b95929f58b0b2bae860 to your computer and use it in GitHub Desktop.
Blame the output of a git-grep. Edited to work under ruby 2.1.X
#!/usr/local/bin/ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
interrupt = false
grep.split("\n").each do |file_with_line|
exit if interrupt
file, line_number, line = file_with_line.split(':', 3)
author = `git blame --line-porcelain -L #{line_number},#{line_number} #{file} | sed -n 's/^author //p'`
puts "#{ author.rstrip }: \"#{ line.lstrip.rstrip }\""
trap('INT'){interrupt = true}
sleep 0.4
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment