Find the unused templates

Adam had an interesting problem to solve earlier that I helped him with. In Copper, each module has its own template directory. The problem is that there are templates that are no longer being used, but are still in the code. I used this shell script to find the number of times the template appears in the code:

ls -1 | grep html | cut -d"." -f1 | \\
while read line; \\
do \\
  echo -n "$line "; \\
  grep $line ../index.php | wc -l; \\
done;

It can easily be modified to list the zero counts only. We ended up using something more like this, because we can’t be certain that just because a template is listed in the code it’s actually being used. For example, it might be a variable name, or in an unrelated string, or in code that’s commented out.

ls -1 | grep html | cut -d"." -f1 | \\
while read line; \\
do \\
  echo -n "$line "; \\
  grep $line ../index.php; \\
  echo; \\
done | more

They’re the longest strings of bash I’ve had to staple together before. All hail the pipe.

Leave a Reply