Skip to content

Instantly share code, notes, and snippets.

@stereodenis
Last active May 6, 2016 14:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stereodenis/10846043 to your computer and use it in GitHub Desktop.
Save stereodenis/10846043 to your computer and use it in GitHub Desktop.
# It requires ACK - http://betterthangrep.com/
task :find_unused_images do
images = Dir.glob('app/assets/images/**/*')
images_to_delete = []
images.each do |image|
unless File.directory?(image)
# print "\nChecking #{image}..."
print '.'
result = `/Users/stereodenis/bin/ack -1 --type-set=mytype=.rb,.css,.scss,.haml,.coffee,.js,.erb,.en,.th,.html,.slim,.less,.sass #{File.basename(image)}`
if result.empty?
images_to_delete << image
else
end
end
end
puts "\n\nDelete unused files running the command below:"
puts "#{images_to_delete.join(" \n")}\n\n"
puts "-----------------------------------"
puts "rm #{images_to_delete.join(" ")}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment