Created
December 6, 2011 16:08
-
-
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
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 | |
| 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