Now I Have a Blog TooNow I Have a Blog Too Christopher Finke is a software engineer at Mahalo. He is available for birthday parties and bar mitzvahs.

Finding unused entities in your Firefox extensions

If you've maintained a Firefox extension for any amount of time, you know that you can accumulate unused entities as you change the UI or add/remove features. They just pile up in your .dtd and .properties files, taking up space. Here's a bash script that will list out any entities or entries in .properties files in your extension that is no longer being used so that you can prune them out.

Usage: $ ./unused-entities.sh path/to/locale-directory/ path/to/content-directory/


#!/bin/bash

echo "Unused entities:"

for dtdfile in `ls $1*.dtd`
do
	awk '/<!ENTITY/ {print $2}' < $dtdfile | while read line
	do
		search=`grep -R "${line}" "$2"`
		if [ "$search" == "" ]
		then
			echo "${line}";
		fi
	done;
done;

echo ""
echo "Unused properties:"

for propfile in `ls $1*.properties`
do
	awk -F "=" '{if (!($2 == "")) { print $1 }}' < $propfile | while read line
	do
		search=`grep -R "${line}" "$2"`
		if [ "$search" == "" ]
		then
			echo "${line}";
		fi
	done;
done;

Leave a Reply