Javascript Beautifier in command-line (and in Geany editor)

Install a Javascript engine (like Mozilla Rhino)

sudo aptitude install rhino

Get the beautifier script (put it somewhere like ~/.bin)


Add the following at the end of beautify.js

print( js_beautify( readFile( arguments[0] )));

Create a shell script that will call it (like ~/.bin/beautifyjs)

java -cp /usr/share/java/js.jar ~/.bin/beautify.js $*

Make sure to set it executable

chmod +x ~/.bin/beautifyjs

Use it from command-line

At least to check that it works !

~/.bin/beautifyjs /your/file.js

Or in Geany Editor

  • Open a Javascript file

  • Open menu Build > Define Build Commands

  • Create a new entry (like beautify)

  • In command, enter the following

    ~/.bin/beautifyjs %f > /tmp/tmpfile.js && geany /tmp/tmpfile.js
  • In working directory, enter %d

#tips, #javascript - Posted in the Dev category