clean
your source code and files in a directory (recursively) from tab
characters and trailing spaces.
Please write clean code. You shouldn't have to use this often, and never for your own code!
Don't be reckless. Some files should have tab characters or trailing whitespace. Read all of the usage below and know your project before you go changing anything.
Within your working directory (e.g. a project directory):
clean | sh
The default tab width is 4 when the tab characters are replaced. There are two ways to change this value:
- local:
clean
takes a parameter of the width. e.g.clean 2
- global: Set the
TABWIDTH
environment variable. This can be done by addingexport TABWIDTH=2
to~/.bashrc
or equivalent.
The clean
command alone produces shell commands to be run.
It is recommend that you run clean
before clean | sh
, so you
can assert you won't be running or removing anything unintended (changing
files that shouldn't be changed).
You can use grep to choose only files you want to modify:
# within a 'models' subdirectory (at any depth)
clean | grep '/models/' | sh
# within the immediate 'models' directory
clean | grep ' ./models/' | sh
# files ending in '.txt'
clean | grep '\.txt ' | sh
To reiterate, remember to check the output before piping to shell.
git clone https://github.com/lukedmor/clean
sudo cp clean/clean /usr/local/bin/