Skip to content

Instantly share code, notes, and snippets.

@viktorkelemen
Created April 4, 2013 14:41
Show Gist options
  • Select an option

  • Save viktorkelemen/5310912 to your computer and use it in GitHub Desktop.

Select an option

Save viktorkelemen/5310912 to your computer and use it in GitHub Desktop.
Extending git grep with git blame
#!/usr/local/bin/ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
interrupt = false
grep.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 }: \"#{ line.lstrip.rstrip }\""
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