Skip to content

The open source coding agent.

TypeScript

feat: add shfmt formatter for shell scripts (#6204)

jab0e4408ecfd1
diff --git a/packages/opencode/src/format/formatter.ts b/packages/opencode/src/format/formatter.ts
index 954940f8db2..90c48b05c2a 100644
--- a/packages/opencode/src/format/formatter.ts
+++ b/packages/opencode/src/format/formatter.ts
@@ -313,3 +313,12 @@ export const gleam: Info = {
return Bun.which("gleam") !== null
},
}
+
+export const shfmt: Info = {
+ name: "shfmt",
+ command: ["shfmt", "-w", "$FILE"],
+ extensions: [".sh", ".bash"],
+ async enabled() {
+ return Bun.which("shfmt") !== null
+ },
+}
diff --git a/packages/web/src/content/docs/formatters.mdx b/packages/web/src/content/docs/formatters.mdx
index fa915f116d4..2c0687b8ea5 100644
--- a/packages/web/src/content/docs/formatters.mdx
+++ b/packages/web/src/content/docs/formatters.mdx
@@ -30,6 +30,7 @@ OpenCode comes with several built-in formatters for popular languages and framew
| ocamlformat | .ml, .mli | `ocamlformat` command available and `.ocamlformat` config file |
| terraform | .tf, .tfvars | `terraform` command available |
| gleam | .gleam | `gleam` command available |
+| shfmt | .sh, .bash | `shfmt` command available |
| oxfmt (Experimental) | .js, .jsx, .ts, .tsx | `oxfmt` dependency in `package.json` and an [experimental env variable flag](/docs/cli/#experimental) |
So if your project has `prettier` in your `package.json`, OpenCode will automatically use it.