Created
December 1, 2014 15:41
-
-
Save 3-n/61be96d172a6b92c9f87 to your computer and use it in GitHub Desktop.
A messy way to check which images may be missing in an ios application
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
#!/bin/sh | |
#./retina.sh directory file_suffix_for_reference file_suffix_to_look_for [-v] | |
# for example: | |
#./retina.sh Images.xcassets 2x 3x [-v] | |
counter=1 | |
file_list=() | |
while IFS= read -d $'\0' -r file ; do | |
file_list=("${file_list[@]}" "$file") | |
echo -en "\rscanning tree, please wait... $counter entries processed" | |
counter=$((counter+1)) | |
done < <(find "$1" -type f -print0) | |
echo "" | |
echo "done, starting doing stuff, gonna print something eventually" | |
modecheck='3x' | |
moderef="$2" | |
modecheck="$3" | |
mode=$modecheck | |
echo "reference "$moderef | |
echo "look for "$modecheck | |
switches="$4" | |
res1x='' | |
res2x='@2x' | |
res3x='@3x' | |
if [ "$moderef" == "1x" ]; then | |
resref="" | |
fi | |
if [ "$moderef" == "2x" ]; then | |
resref="\\"$res2x | |
fi | |
if [ "$moderef" == "3x" ]; then | |
resref="\\"$res3x | |
fi | |
rm -rf fl_missing$moderef$modecheck | |
rm -rf fl_duplicates$moderef$modecheck | |
mkdir fl_missing$moderef$modecheck | |
counter=1 | |
for png in "${file_list[@]}" | |
do | |
regex="${resref}\\.png\$" | |
# echo "$png" | |
# echo "BAIL?" | |
if [ "$moderef" == "1x" ]; then | |
# echo "BAIL?" | |
if [[ "$png" == *"@2x"* || "$png" == *"@3x"* ]]; then | |
# echo "BAIL!" | |
continue | |
fi | |
fi | |
if ! [[ "$png" =~ ${regex} ]]; then | |
# echo "bail" | |
continue | |
fi | |
if [ "$switches" == "-v" ]; then | |
echo "checking "$png | |
fi | |
if [ "$moderef" == "1x" ]; then | |
# echo "HEREEEEEE1x" | |
name1x=$(basename "$png") | |
name2x="${name1x/".png"/@2x.png}" | |
name3x="${name1x/".png"/@3x.png}" | |
fi | |
if [ "$moderef" == "2x" ]; then | |
# echo "HEREEEEEE2x" | |
name2x=$(basename "$png") | |
name3x="${name2x/$res2x/$res3x}" | |
name1x="${name2x/$res2x/$res1x}" | |
fi | |
if [ "$moderef" == "3x" ]; then | |
# echo "HEREEEEEE3x" | |
name3x=$(basename "$png") | |
name2x="${name3x/$res3x/$res2x}" | |
name1x="${name3x/$res3x/$res1x}" | |
fi | |
# echo "name 1x "$name1x | |
# echo "name 2x "$name2x | |
# echo "name 3x "$name3x | |
fullname1x=() | |
while IFS= read -d $'\0' -r file ; do | |
fullname1x=("${fullname1x[@]}" "$file") | |
done < <(find "$1" -name "$name1x" -type f -print0) | |
fullname2x=() | |
while IFS= read -d $'\0' -r file ; do | |
fullname2x=("${fullname2x[@]}" "$file") | |
done < <(find "$1" -name "$name2x" -type f -print0) | |
fullname3x=() | |
while IFS= read -d $'\0' -r file ; do | |
fullname3x=("${fullname3x[@]}" "$file") | |
done < <(find "$1" -name "$name3x" -type f -print0) | |
nameref="$name2x" | |
namechecked="$name3x" | |
fullnameref=$fullname2x | |
fullnamechecked=$fullname3x | |
# echo "namechecked "$namechecked | |
if [ "$modecheck" == "1x" ]; then | |
namechecked="$name1x" | |
fullnamechecked=$fullname1x | |
fi | |
if [ "$modecheck" == "2x" ]; then | |
namechecked="$name2x" | |
fullnamechecked=$fullname2x | |
fi | |
if [ "$modecheck" == "3x" ]; then | |
namechecked="$name3x" | |
fullnamechecked=$fullname3x | |
fi | |
if [ "$moderef" == "1x" ]; then | |
nameref="$name1x" | |
fullnameref=$fullname1x | |
fi | |
if [ "$moderef" == "2x" ]; then | |
nameref="$name2x" | |
fullnameref=$fullname2x | |
fi | |
if [ "$moderef" == "3x" ]; then | |
nameref="$name3x" | |
fullnameref=$fullname3x | |
fi | |
# echo "namechecked "$namechecked | |
# echo "--" | |
# echo "$nameref" | |
# echo "$namechecked" | |
# echo "$fullnameref" | |
# echo "$fullnamechecked" | |
# echo "--" | |
if [ ${#fullnameref[@]} -eq 1 ]; then | |
if [ ! -f "${fullnamechecked[0]}" ]; then | |
echo " MISSING ""$nameref" | |
echo " copying ""${fullnameref[0]}"" to fl_missing"$moderef$modecheck | |
cp "${fullnameref[0]}" fl_missing$moderef$modecheck | |
fi | |
else | |
if [ ! -f "${fullnamechecked[0]}" ]; then | |
echo " DUPLICATE and MISSING ""$nameref" | |
else | |
echo " DUPLICATE ""$nameref" | |
fi | |
for file in "${fullnameref[@]}" | |
do | |
echo " here: ""${file}" | |
echo " copying ""${file}"" to fl_duplicates"$moderef$modecheck | |
mkdir -p fl_duplicates$moderef$modecheck | |
cp "${file}" fl_duplicates$moderef$modecheck/ | |
done | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment