My favorites | Sign in
Project Home Downloads Issues Source
Project Information
Members
Links
  • External links
  • PyPI

Status

This project has beta status: use at your own risk!

Please submit bugs as you find them.

Summary

Cleanup whitespace in text files:

  • Unify indentation by replacing leading tabs with spaces (or vice versa)
  • Strip trailing whitespace
  • Make sure the file ends with exactly one line break
  • Unify line delimiters to Unix, Windows, or Mac style
  • Optionally change indentation depth

Usage

Preconditions: Python is required, EasyInstall recommended.

Install like this:

$sudo easy_install -U tabfix

or on Windows:

>easy_install -U tabfix

Syntax:

$ tabfix --help
Usage: tabfix [options] [PATH]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -s N, --tab-size=N    set target tab size (default: 4)
  --input-tab-size=N    assume tab size of input file to be N (default: target
                        tab size)
  -t, --tabbify         uses tabs for indentation (default: use spaces
  --line-separator=MODE
                        line separator used for output file. Possible values:
                        Unix, Windows, Mac, LF, CRLF, CR (default: keep mode
                        from input file)
  -x, --execute         turn off the dry-run mode (which is ON by default),
                        that would just print status messages but does not
                        change anything
  -m MATCHLIST, --match=MATCHLIST
                        match this file name pattern (option may be repeated)
  -r, --recursive       visit sub directories
  -o FILENAME, --target=FILENAME
                        name of output file
  --no-backup           prevent creation of backup files (*.bak)
  -q, --quiet           don't print status messages to stdout (verbosity 0)
  -v, --verbose         increment verbosity to 2 (use -vv for 3, ...)
  --zip-backup          add backups of modified files to a zip-file

See also http://tabfix.googlecode.com
$ 

Example

Fix whitespace in all JavaScript and HTML files in the current directory and all sub directories.
Convert space-indents to tabs, using one tab for 4 spaces.
Source files will be replaced, a backup file is created with *.bak extension.

> tabfix -t -r -m*.js -m*.html

By default, the script is in dry-run mode, so only status messages are printed, but no files are changed.
We have to add the -x option to force 'execute':

> tabfix -t -r -m*.js -m*.html -x

Example

Fix whitespace (using 4 spaces for indentation) in two source files:

> tabfix foo.js bar.html

Example

Cleanup test.html and write output to test2.html. Convert tabs to 4 spaces, assuming original tab size was 2.
-vv prints all modified lines.
Since we did not pass -x, no files are changed.

>tabfix --input-tab-size=2 test.html -otest2.html -vv
Powered by Google Project Hosting