Skip to content

Instantly share code, notes, and snippets.

@sskirby
Created December 6, 2011 16:08
Show Gist options
  • Save sskirby/1438733 to your computer and use it in GitHub Desktop.
Save sskirby/1438733 to your computer and use it in GitHub Desktop.
Ruby script to open a vim window for each file whose content matches a regex
#!/usr/bin/env ruby
if ARGV.size < 2
puts 'grepfactor <search string> <location1>[ <location2> <location3>...]'
exit
end
lines = []
puts 'grepping....'
`grep -rn --color #{ARGV[0]} #{ARGV[1..-1].join(" ")}|grep -v swp`.each do |l|
if l =~ /:/
lines << {\
:path => l.split(':').first.strip,
:line_number => l.split(':')[1].strip}
puts "adding #{l}"
else
puts "ignoring #{l}"
end
end
puts "\n\n------------------------"
puts 'refactor time!'
puts "------------------------\n\n"
#lines.each do |line|
#puts "opening #{line[:path]} at #{line[:line_number]}"
#`gvim -p #{line[:path]} +#{line[:line_number]}`
#end
files = lines.map {|l| l[:path] }.uniq
`gvim -p #{files.join(' ')}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment