aboutsummaryrefslogtreecommitdiff
path: root/tools/remove-unused-strings.sh
blob: 2b0c6eaf436899cf78786224dbd5b4c8039ac75f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh

RESDIR=WordPress/src/main/res/

unused_strings=$(lint --check  UnusedResources . \
    | grep "$RESDIR/values/strings.xml" \
    | grep -o "R\.string\.[^ ]*" \
    | sed "s/R.string.//" \
    | tr "\n" "|" \
    | sed 's/|/"|"/g' \
    | sed 's/^/"/' \
    | sed 's/|"$//')

if [ "$unused_strings"x = x ]; then
    echo $RESDIR/values/strings.xml is already clean
else
    grep -E -v "$unused_strings" $RESDIR/values/strings.xml > tmp.xml
    mv tmp.xml $RESDIR/values/strings.xml
    echo $(echo "$unused_strings" | sed "s/[^|]//g" | wc -c) strings removed
fi