-
-
Save chrrasmussen/281dd029f42114d0cc69 to your computer and use it in GitHub Desktop.
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 | |
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