Skip to content

Instantly share code, notes, and snippets.

@inodb
Forked from nas/gbgrep
Created November 5, 2015 23:14
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 inodb/6fa8d874ab2050020a82 to your computer and use it in GitHub Desktop.
Save inodb/6fa8d874ab2050020a82 to your computer and use it in GitHub Desktop.
git blame with grep
#!/usr/bin/env 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} | head -1"
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