Created
January 17, 2014 09:29
-
-
Save sugarmo/8470598 to your computer and use it in GitHub Desktop.
Find unused images
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
#!/bin/bash | |
# Escape code | |
esc=`echo -en "\033"` | |
# Set colors | |
cc_red="${esc}[0;31m" | |
cc_green="${esc}[0;32m" | |
cc_yellow="${esc}[0;33m" | |
cc_blue="${esc}[0;34m" | |
cc_normal=`echo -en "${esc}[m\017"` | |
echo "Creating files index..." | |
files=(`find . -type f \( ! -path './backup/*' ! -path './External/*' -and \( -name '*.xib' -or -name '*.[mh]' -or -name '*.storyboard' -or -name '*.mm' -or -name '*.html' -or -name '*.css' -or -name '*.js' -or -name '*.plist' \) \) -exec echo ''{}'' \;`) | |
echo "Creating images index..." | |
images=(`find . -type f \( ! -path './backup/*' ! -path './External/*' -and \( -name '*.png' -or -name '*.jpg' -or -name '*.jpeg' \) \) -exec echo ''{}'' \;`) | |
image_count=${#images[@]} | |
i=0 | |
unused_count=0 | |
echo 'Unused file list:' > ./find-unused_images.log | |
for image in ${images[*]} | |
do | |
let "i += 1" | |
name=`basename -s .png $image` | |
name=`basename -s .jpg $name` | |
name=`basename -s .jpeg $name` | |
name=`basename -s @2x $name` | |
if ! grep -qhs "\b$name\b" ${files[*]}; then | |
let "unused_count += 1" | |
echo "($i / $image_count) $image ${cc_red}not referenced${cc_normal}" | |
echo $image >> ./find-unused_images.log | |
else | |
echo "($i / $image_count) $image ${cc_green}checked${cc_normal}." | |
fi | |
done | |
echo "$unused_count unused images found. See find-unused_images.log for found list." | |
echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the script hung for me when grep'ing so I simplified it a bit:
Given the output you can do a regex search for \n.*\n to find unused images (unused images will just have "searching for name" outputted with empty space before and after)