Created
May 8, 2014 02:35
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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