My text editor of choice on the Mac is TextWrangler. It’s lightweight and it has pretty much all you need from a text editor. In particular, I like that I can SFTP into my development server.
One issue that bugged me lately was when I opened an unindented, unformatted XML file. Basically, it looked a mess and there was no way to tidy the file up so that I could read it easily.
We want to add a UNIX script to TextWrangler so it can format an XML file… to do this, do this…
- Open TextWrangler and open a new text file.
- Copy and paste the code below into this file.
#!/bin/sh XMLLINT_INDENT=$'\t' xmllint --format --encode utf-8 -
- Save the file, something like Tidy XML.sh, in the
~/Library/Application Support/TextWrangler/Text Filters/folder.
- Now anytime you want to format an XML file, just go to the Text menu and select the Tidy XML.sh script and BOOM, neat tidy XML.
This is an interesting facility to extend an already great text editor, and I will be looking into more cool scripts that can hopefully lessen my daily annoyances.
UPDATED:: Added UTF8 encoding, thanks Rolan.
UPDATED:: Added a post to format PHP code in TextWrangler.
UPDATED:: Updated for TextWrangler version 4.5.8.