# shfmt

> Shell script formatter, with a Go shell parser and interpreter library (mvdan/sh)

Source: https://talira.ai/catalog/shfmt-bynaz0ma
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Command-line tool, Library
- Categories: [developer tools / formatting](https://talira.ai/categories/developer-tools/formatting)
- Licence: BSD-3-Clause[^4]
- Pricing: Free and open source[^4]
- Free tier: yes[^4]
- Backed by: [Daniel Martí](https://talira.ai/orgs/daniel-marti.md)

shfmt formats POSIX Shell, Bash, Zsh and mksh scripts in one consistent style, and converts scripts to and from a JSON syntax tree. It comes from mvdan/sh, a pure-Go shell library whose packages parse scripts into a syntax tree, split, quote and expand words like a shell, and interpret scripts without a system shell, including on Windows, with handlers that control what a script can run and access.

## Links

- GitHub: https://github.com/mvdan/sh
- Docs: https://pkg.go.dev/mvdan.cc/sh/v3

## Ways to install

### Package managers

- [Homebrew](https://talira.ai/catalog/homebrew-djy17yn9.md): <https://formulae.brew.sh/formula/shfmt>[^1]
- [mise](https://talira.ai/catalog/mise-0axr08xw.md): <https://mise-versions.jdx.dev/tools/shfmt>[^2]

## Problems it solves

- format my shell scripts consistently in CI
- check bash scripts are formatted in a pre-commit hook
- run shell scripts from a Go program without a system shell

## Features

- Formats POSIX Shell, Bash, Zsh and mksh scripts
- Converts between shell and a JSON syntax tree
- Go parser that builds a shell syntax tree
- Interpreter that runs scripts without a system shell, including on Windows
- Shell-style word splitting, quoting, expansion and globbing in Go
- Docker images with Alpine variants
- Editor integrations for VS Code, JetBrains IDEs, Vim, Emacs and Prettier

## Limitations

- The formatter cannot be turned off for ranges of lines[^3]
- Does not support the $(( and (( ambiguity; space the operands[^3]
- Subshells in the interpreter run as goroutines, so real PIDs and file descriptors cannot be used[^3]

## Trust

Overall: 0.69 out of 1.
Signals: maintenance 1.00, adoption 0.79, momentum 0.56, community 0.82, backing 0.30, extensibility 0.00.

- last commit 4 days ago
- 333 commits in the last 90 days
- latest release v3.14.1 2 months ago
- 9.2k GitHub stars
- 112 contributors
- accepts sponsorship (Github)
- 11k Homebrew installs in 30 days
- backed by Daniel Martí

## Alternatives

- [pretty-quick](https://talira.ai/catalog/pretty-quick-vjah55ap.md): Runs Prettier on only the files you changed, with a pre-commit mode

## Sources

[^1]: https://formulae.brew.sh/api/formula.json (checked 28 Nov 2026)
[^2]: https://mise-versions.jdx.dev/tools.json (checked 28 Nov 2026)
[^3]: https://github.com/mvdan/sh/blob/master/README.md (checked 28 Nov 2026)
[^4]: https://github.com/mvdan/sh/blob/master/LICENSE (checked 28 Nov 2026)
