-
-
Save artsyca/5759418 to your computer and use it in GitHub Desktop.
Updated to use newer ack. Only outputs the filenames. You can use: $ rake find_unused_images > unused_images.txt $ xargs rm < ./unused_images.txt to delete them all! Also, supports multiple directories.. and filenames are shellescaped.
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
| # 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 = `ack -1 -G '(app|public)' --ruby --html --css --js #{File.basename(image)}` | |
| if result.empty? | |
| images_to_delete << image | |
| else | |
| end | |
| end | |
| end | |
| puts "\n\nDelete unused files running the command below:" | |
| 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