Revamped template manager - BACKUP YOUR TEMPLATES

A significant portion of template manager has been rewritten. This
version has gone through some testing and the obvious bugs have been
found, but there are bound to be plenty left. You have been warned. Back
up your template files. And reread the documentation in the script file,
because a LOT has changed. Changelog:
https://gist.github.com/lyger/9620712