Skip to content

Instantly share code, notes, and snippets.

@dkubb
Created December 11, 2015 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkubb/4cefe3882353b4854d7b to your computer and use it in GitHub Desktop.
Save dkubb/4cefe3882353b4854d7b to your computer and use it in GitHub Desktop.
#!/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