Advertisement
quark_zju

rails_model_bulk_renme

Aug 3rd, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.54 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'active_support/core_ext/string'
  4.  
  5. if ARGV.size < 2
  6.   puts "#{$0} old_string new_string"
  7.   puts "example: #{$0} problem_set contest"
  8.   exit
  9. end
  10.  
  11. renames = { ARGV[0] => ARGV[1], ARGV[0].camelcase => ARGV[1].camelcase }
  12.  
  13. # directory names, file names, file content
  14. [ 'd', 'f' ].each { |p| renames.each { |f, t| system " rename #{f} #{t} `find  \\( ! -regex '.*/\\..*' \\) -type #{p}` " } }
  15. renames.each { |f, t| system "find  \\( ! -regex '.*/\\..*' \\) -type f | while read f; do sed -i 's/#{f}/#{t}/g' $f; done" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement