Created
June 4, 2018 17:53
-
-
Save Bhacaz/693a20b0fdff998d85ff8477e7fa8c69 to your computer and use it in GitHub Desktop.
Script to add `# frozen_string_literal: true` on top of a file. Useful to add has a external tool in RubyMine
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 | |
file_path = ARGV.first | |
puts '' | |
unless file_path | |
puts 'You must provide a file path' | |
puts ' Ex: ruby add_frozen_string.rb /path/to/file.rb' | |
exit 1 | |
end | |
puts "Opening: #{file_path}" | |
f = File.open(file_path, "r+") | |
lines = f.readlines | |
f.close | |
if lines.first == "# frozen_string_literal: true\n" | |
puts 'Already there.' | |
exit 0 | |
end | |
lines = ["# frozen_string_literal: true\n\n"] + lines | |
output = File.new(file_path, "w") | |
lines.each { |line| output.write line } | |
output.close | |
puts 'Done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment