-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathunused-image.sh
More file actions
executable file
·99 lines (81 loc) · 2.24 KB
/
unused-image.sh
File metadata and controls
executable file
·99 lines (81 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
PROGNAME=$(basename "$0")
PROGDIR=$(dirname "$0")
usage()
{
echo "Usage: $PROGNAME [option] -p path-of-project"
echo ""
echo "-p Specifyed the path of your project"
echo "-r Remove unused image file"
echo "-h Show this message"
exit 1
}
PRJ_ROOT=$1
REMOVE=false
COUNT=0
while getopts ":rp:" optname
do
case "$optname" in
"p")
PRJ_ROOT=$OPTARG # specifyed the project root
;;
"r")
REMOVE=true # remove unused image resource
;;
"?")
usage
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
#echo "OPTIND is now $OPTIND"
done
check_files=`find $PRJ_ROOT -name '*.xib' -o -name '*.storyboard' -o -name '*.[mh]' -o -name '*.pch' -o -name '*.java' -o -name '*.xml'`
imagesetdirname=".imageset"
for png in `find $PRJ_ROOT -name '*.png'`
do
match_name=`basename $png`
suffix1="@2x.png"
suffix2=".9.png"
suffix3=".png"
suffix4="@3x.png"
if [[ ${match_name/${suffix1}//} != $match_name ]]; then
match_name=${match_name%$suffix1}
elif [[ ${match_name/${suffix4}//} != $match_name ]]; then
match_name=${match_name%$suffix4}
elif [[ ${match_name/${suffix2}//} != $match_name ]]; then
match_name=${match_name%$suffix2}
else
match_name=${match_name%$suffix3}
fi
dir_name=`dirname $png`
if [[ $dir_name =~ .bundle$ ]] || [[ $dir_name =~ .appiconset$ ]] || [[ $dir_name =~ .launchimage$ ]]; then
continue
fi
#if is imageset,use imageset's name as match_name
if [[ $dir_name =~ .imageset$ ]]; then
match_name=`basename $dir_name`
match_name=${match_name%$imagesetdirname}
fi
referenced=false
for file in `echo $check_files | sed 's/\n/ /g'`
do
if grep -sqh "$match_name" "$file"; then
referenced=true
fi
done
if ! $referenced ; then
echo "The '$png' was not referenced in any file"
COUNT=`expr $COUNT + 1`
if $REMOVE ; then
echo "Do remove unused image file '$png'"
rm -f $png
fi
fi
done
echo "============= Total $COUNT unused image files ============="