Last active
December 14, 2015 21:49
-
-
Save gentooboontoo/5154258 to your computer and use it in GitHub Desktop.
Insert missing utf-8 encoding magic comment to existing ruby files. USAGE: ruby insert-utf8-encoding.rb <dir>
This file contains 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 | |
# encoding: utf-8 | |
Dir[File.join(ARGV[0], '**', '*.{rb,rake}')].each do |file| | |
lines = File.open(file).readlines | |
next if lines[0].match(/#\s+(?:en)?coding:\s+utf-8/i) | |
puts "Adding encoding magic comment to #{file}" | |
File.open(file, 'w') do |io| | |
io << "# encoding: utf-8\n\n" | |
io << lines.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment