Created
October 1, 2014 20:30
-
-
Save jeffkreeftmeijer/c9f9416c3d9f969e6845 to your computer and use it in GitHub Desktop.
Automatically remove magic encoding comments http://shorts.jeffkreeftmeijer.com/2014/automatically_remove_magic_encoding_comments/
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 | |
Dir['**/*.rb'].each do |path| | |
lines = File.readlines(path) | |
new_lines = lines.dup | |
lines.each do |line| | |
if line =~ /^# encoding: utf-8/i || line !~ /\S/ | |
new_lines.delete_at(new_lines.index(line)) | |
else | |
break | |
end | |
end | |
print '.' | |
File.open(path, 'w') do |file| | |
file.write(new_lines.join) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment