Skip to content

Instantly share code, notes, and snippets.

@nas
Created May 20, 2011 18:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save nas/983471 to your computer and use it in GitHub Desktop.
Save nas/983471 to your computer and use it in GitHub Desktop.
git blame with grep
#!/usr/local/bin/ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
puts "\n-----------------------------------------------------------"
puts "GREP RESULT"
puts '-----------------------------------------------------------'
puts grep
files = grep.scan /.*\:\d+/
interrupt = false
files.each do |file_with_line|
exit if interrupt
puts "\n-----------------------------------------------------------"
puts file_with_line
puts '-----------------------------------------------------------'
file, line = file_with_line.split(':')
system "git blame -L #{line} #{file}"
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