-
-
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/ | |
# Modified from https://gist.github.com/rafaelp/4467738 | |
# Please add the following filetypes to your .ackrc | |
# --type-set=haml=.haml | |
# --type-set=sass=.sass | |
# --type-set=scss=.scss | |
# --type-set=erb=.erb | |
# --type-set=coffee=.coffee | |
# Based on: https://github.com/docwhat/homedir-examples/pull/3 | |
task :find_unused_images do | |
# Look in two folders by default. | |
directories = [ | |
'app/assets/images/**/*', | |
'public/images/**/*' | |
] | |
#puts "=======================\nDelete unused files below:" | |
directories.each do |path| | |
images = Dir.glob(path) | |
images.each do |image| | |
unless File.directory?(image) | |
result = `ack -1 --ignore-directory=tmp --ignore-directory=log --ruby --html --css --js --sass --scss --coffee --erb --haml #{File.basename(image).shellescape}` | |
if result.empty? | |
print "./" + image.shellescape + "\n" | |
end | |
end #unless File.directory?(image) | |
end #images.each | |
end #directories.each | |
end #task |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment