I\'m looking for something similiar to indent but for (bash) scripts. Console only, no colorizing, etc.
Do you know of one ?
shfmt works very well.
You can format bash scripts and also check the formatting from pre-commit hooks.
# reformat
shfmt -l -w script.sh
# check if the formatting is OK
shfmt -d script.sh
# works on the whole directory as well
shfmt -l -w .
The only option absent is that it does not reformat according to line length (yet).
Since it is written in go you can just download the binary for most platforms, e.g. for Travis (.travis.yml
):
install:
- curl -LsS -o ~/shfmt https://github.com/mvdan/sh/releases/download/v3.1.2/shfmt_v3.1.2_linux_amd64
- chmod +x ~/shfmt
script:
- ~/shfmt -d .
There is also a cross compiled js version on npm and a lot of editor plugins (see related projects)