Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use git grep, and then blame to get the author, line number and detail
#!/usr/bin/env ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
interrupt = false
grep.lines.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 } #{file} +#{line_number} #{ line.lstrip.rstrip }"
trap('INT'){interrupt = true}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment