Skip to content

Instantly share code, notes, and snippets.

@chrrasmussen
Forked from travisjeffery/decommentify
Created August 21, 2014 00:12
Show Gist options
  • Save chrrasmussen/281dd029f42114d0cc69 to your computer and use it in GitHub Desktop.
Save chrrasmussen/281dd029f42114d0cc69 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
search_dir = ARGV[0] || "."
files = Dir.glob("#{search_dir}/**/*.{h,m,swift}")
if files.length > 0
puts "Found the following header or implementation files in '#{search_dir}':"
files.each do |filepath|
puts filepath
end
puts
puts "Proceed? (y/N)"
should_proceed = STDIN.gets.chomp.downcase == "y"
if should_proceed
remove_comment_headers(files)
puts "Done"
else
puts "Aborted"
end
else
puts "Found no header or implementation files in '#{search_dir}'"
end
BEGIN {
def remove_comment_headers(files)
regexp = /^\/\/.*$\n/
files.each do |filepath|
lines = []
replace = true
IO.readlines(filepath).each do |line|
if !replace || !replace = line.match(regexp)
lines << line
end
end
lines.shift if lines[0] == "\n"
File.open(filepath, 'w') { |f| f.puts lines }
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment