Created
December 11, 2015 09:24
-
-
Save dkubb/4cefe3882353b4854d7b to your computer and use it in GitHub Desktop.
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 | |
require 'filemagic' | |
require 'pathname' | |
require 'parser/current' | |
require 'unparser' | |
RUBY_TYPE = 'ruby script'.freeze | |
# TODO: handle stdin | |
ARGV.flat_map(&Pathname.method(:glob)).select(&:file?).each do |path| | |
type = FileMagic.open(FileMagic::MAGIC_NONE) { |fm| fm.file(path.to_path) } | |
next unless type.include?(RUBY_TYPE) | |
path.write( | |
Unparser.unparse(*Parser::CurrentRuby.parse_file_with_comments(path)) | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment