shfmt Plugin
Shell script formatter supporting bash, POSIX shell, mksh, and zsh.
Commands
Format
shfmt format run— Format a shell scriptshfmt format write— Format and write in-placeshfmt format list— List unformatted shell scripts
Usage Examples
- "Format this shell script"
- "Auto-fix indentation in my bash script"
- "Show which scripts need formatting"
- "Format all .sh files in the project"
Installation
go install mvdan.cc/sh/v3/cmd/shfmt@latest
Examples
# Print formatted script to stdout
shfmt script.sh
# Write in-place
shfmt -w script.sh
# List unformatted files
shfmt -l *.sh
# Set indent width
shfmt -i 2 script.sh
# Use POSIX mode
shfmt -ln posix script.sh
# Format all recursively
shfmt -w .