Beautify JavaScript from TextMate or CLI | 6 Comments
Posted in Code, Software on 14th January 2008, 10:24 am by Stuart
As Einars has pointed out this functionality is part of the built-in JavaScript Bundle under “Reformat Document”. I’ll leave the rest of this post here as it does provide an example of how to set-up a command with an existing PHP script and if you’re not a TextMate user then this will work as a CLI script too and you can find more info on using PHP for CLI in TextMate here
I’ve just been reviewing some code that’s minned and I remembered looking at beautifier for JavaScript recently that was designed to convert minned code back to something more readable. The script I remembered was this one: http://elfz.laacz.lv/beautify/. The beautifier makes it really easy to dive into source to view code without having to resort to getting hold of the un-minned source. This is also especially useful when you don’t have access to the un-minned source.
By taking the PHP source and converting it to CLI, I was able to add a beautify JS command to TextMate.
Thanks very much to Einars "elfz" Lielmanis for making this script freely available it made it really easy to add this functionality to TextMate. My additions are highlighted.
#!/usr/bin/env php
<?php
…See the main Beautify.js source here…
$fstat = fstat(STDIN);
$stdin = fread(STDIN,$fstat['size']);
echo js_beautify($stdin);
?>
The settings for the command are as follows:
- Save:
- Nothing
- Input:
- Selected Text or Document
- Output:
- Create New Document
With the above you can either build your own command or download this one pre-made: BeautifyJS.zip

Pingback: Javascript
Pingback: Vim çš„ JavaScript ç¸®æŽ’æ ¼å¼æœ€ä½³åŒ– 外掛 | TechNow 當代科技