Rewrite pre-commit hook

Since more than just basic functionality is now needed (i.e. adding
linting), rewrite in Python for convenience. Also add linting.