Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:textarcana/snippets

  • Loading branch information...
commit 8f7fc6a1a48aee82e6ddd43fc57f143f7ca6759a 2 parents c4d1cbb + 3284017
Noah Sussman authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 git/grep_blame.rb
View
32 git/grep_blame.rb
@@ -0,0 +1,32 @@
+#!/usr/bin/env ruby
+
+# Grep for a string and then git blame the lines that match. Written
+# by Ramin Bozorgzadeh.
+#
+# Eg:
+# grep_blame.rb "attr\([\"\']checked[\"\']\)" htdocs/assets/js
+
+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},#{line} #{file}"
+
+ trap('INT'){interrupt = true}
+ sleep 0.4
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.