Skip to content

Instantly share code, notes, and snippets.

@aelam
Created April 22, 2016 14:46
Show Gist options
  • Save aelam/f169f88149d7eaf1c2258b25150b3ae9 to your computer and use it in GitHub Desktop.
Save aelam/f169f88149d7eaf1c2258b25150b3ae9 to your computer and use it in GitHub Desktop.
Find Unused Images in Xcode Projects
#!/bin/sh
echo $1
FINDING_PATH=$1
if [ -z "$FINDING_PATH" ]
then
echo "FINDING_PATH is empty, will use current path"
FINDING_PATH='.'
fi
# PROJ=`find $FINDING_PATH -name '*.[xib|h|m]' -o -name '*.[mh]'`
PROJ=`find $FINDING_PATH -name "*.png" -o -name "*.jpg" -o -name "*.[hm]"`
#
# 1. 找出所有的可能用到了图片名字的文件名
# 2. 找出所有的png
# 3. 如果png在xxx.imageset文件夹下面 则处理提取出xxx 然后继续下一步
# 如果不属于*.imageset则直接进行下一步
# 4. 用图片名匹配第一步查找出的文件的内容
#
for png in `find $FINDING_PATH -name '*.png'`
do
maybe_imageset_dirname=`dirname $png`
maybe_imageset_ext="${maybe_imageset_dirname##*.}"
if [ "$maybe_imageset_ext" = "imageset" ]; then
temp=`basename $maybe_imageset_dirname` # 消除路径
temp2="${temp%.*}" # 消除后缀
name=$temp2
else
name=`basename $png`
fi
if ! grep -qhs "${name}" "$PROJ"; then
echo "\n$png is not referenced\n
$name
"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment