2025-03-14 21:59:59 -06:00
|
|
|
# shfmt
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
> Shell parser, formatter, and interpreter.
|
|
|
|
|
> More information: <https://pkg.go.dev/mvdan.cc/sh#section-readme>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Print a formatted version of a shell script:
|
|
|
|
|
|
|
|
|
|
`shfmt {{path/to/file}}`
|
|
|
|
|
|
|
|
|
|
- List unformatted files:
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`shfmt {{[-l|--list]}} {{path/to/directory}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Write the result to the file instead of printing it to the terminal:
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`shfmt {{[-w|--write]}} {{path/to/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- Simplify the code, removing redundant pieces of syntax (e.g. removing "$" from vars in expressions):
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
`shfmt {{[-s|--simplify]}} {{path/to/file}}`
|
|
|
|
|
|
|
|
|
|
- Specify the amount of spaces to use for indentation (0 for tabs, which is also the default):
|
|
|
|
|
|
|
|
|
|
`shfmt {{[-i|--indent]}} {{4}} {{path/to/file}}`
|
|
|
|
|
|
|
|
|
|
- Format the code according to Google's style guide:
|
|
|
|
|
|
|
|
|
|
`shfmt {{[-i|--indent]}} 2 {{[-ci|--case-indent]}} {{[-w|--write]}} {{path/to/file}}`
|