Skip to content

Instantly share code, notes, and snippets.

@zhongfox
Created May 8, 2014 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhongfox/6ea3a5a11f6760352ab5 to your computer and use it in GitHub Desktop.
Save zhongfox/6ea3a5a11f6760352ab5 to your computer and use it in GitHub Desktop.
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