Reindent/Format Lua source files to be formatted pretty.

The author of ZeroBrane Studio has a nifty Perl script to pretty Lua source files (.lua).  I grabbed it and put  together a Bash script using it. This will pretty a single .lua source file or all .lua source files in the current directory.  It can traverse down the directory tree for all .lua files and read the indentmash.sh script on usage.
 
This is a Bash script, Window users will need to use Cygwin or Babun for this to work.
 
Credit goes to http://notebook.kulchenko.com/programming/lua-beautifier-in-55-lines-of-perl for the Perl script.
 
Installation and Running the script (requires Terminal window/Shell):

  • Copy/paste the Perl script above into your favorite text editor. Save it to a file named “indentmash.pl”.
     
  • Be sure to edit the Perl script and change the INDENT variable to match your indent style. It’s using 2 spaces for indenting.  Feel free to use tabs ‘\t\t\t\t’ or spaces ’    ’ for indenting. I use 4 spaces.
     
  • Create the bin folder in your Home directory
    $ mkdir $HOME/bin
     
  • Copy the files into your home directory’s bin folder.
    $ cp indentmash.sh $HOME/bin
    $ cp indentmash.pl $HOME/bin
     
  • Make the bash script executable.
    $ chmod 755 $HOME/bin/indentmash.sh

Usage (requires Terminal/Shell):
 
   Pretty a single file:
   ~/bin/indentmash.sh my_source.lua

   Pretty all files in the current directory:
   ~/bin/indentmash.sh
 
Attached is the .zip archive of the bash script.
 
This script is provided as-is, no warranty and use at your own risk. Enjoy!