Created
March 12, 2009 09:21
-
-
Save FiXato/77976 to your computer and use it in GitHub Desktop.
Iterate through dirs in the current directory and do a `git grep` on the given keyword in each one of them.
This file contains hidden or 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 | |
# Iterate through dirs in the current directory and do a `git grep` on the given keyword in each one of them. | |
# Outputs the command and each result. | |
Dir.glob('*/').each do |dir| | |
string = ARGV.join(' ').gsub(/(\W)/) do |match| | |
'\\%s' % match | |
end | |
cmd = "cd #{dir} && git grep #{string}" | |
output = `#{cmd}` | |
next unless output.strip.size > 0 | |
puts cmd | |
puts output.map{|l| ' %s' % l} | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment