Created
June 21, 2013 10:21
-
-
Save dpanda/5830306 to your computer and use it in GitHub Desktop.
Bash script I wrote to find out unused images in a sass project (assuming that all images are in the "img" directory and sass files in the "sass" directory).
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 | |
cd img | |
images=(`ls *.png *.jpg *.jpeg *.gif 2> /dev/null`) # get all images | |
cd ../sass | |
scss=(`ls *.scss */*.scss`) # get all compass files | |
usedImg=() | |
unusedImg=() | |
for i in "${images[@]}"; do # for each image... | |
: | |
used="not-used" | |
for f in "${scss[@]}" ; do # for each compass file... | |
: | |
rule=`cat $f | grep $i` # find out if images is used in any rule | |
if [ "$rule" ] ; then # if so, add it to the "used images" array | |
usedImg=("${usedImg[@]}" "$f \t\t\t\t$i\n") | |
used="" | |
break | |
fi | |
done | |
if [ $used ] ; then # not found in any file: add it to the "unused images" array | |
unusedImg=("${unusedImg[@]}" "$i") | |
fi | |
done | |
# print used and unused images | |
echo "Used images:" | |
echo -e "${usedImg[@]}" | |
echo | |
echo "Unused images, moving them to _unused:" | |
echo "${unusedImg[@]}" | |
# move all unused images to another directory | |
cd ../img | |
mkdir _unused 2> /dev/null | |
for i in "${unusedImg[@]}"; do | |
: | |
mv $i ./_unused | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment