Skip to content

Instantly share code, notes, and snippets.

@FiXato
Created March 12, 2009 09:21
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 FiXato/77976 to your computer and use it in GitHub Desktop.
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.
#!/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