Transpile TypeScript to bash, POSIX sh, PowerShell, or Windows batch with one toolchain and a seamless .ts authoring experience.
- Multi-target output:
--target bash | sh | ps1 | bat - Standard library via
std/*modules (std/io,std/env,std/shell, …) - Environment API:
Env.set/Env.getfromstd/env - Per-target implementations:
switch (TARGET)with compile-time branch folding - Typed errors:
TS2SHELL###codes with source snippets and fix hints - No custom LSP: use built-in TypeScript IntelliSense +
pathsto@ts2shell/std-types
git clone <repository-url>
cd ts2shell
yarn install
yarn buildyarn ts2shell compile examples/hello.ts --target bash -o dist/hello.sh
chmod +x dist/hello.sh
./dist/hello.shCompile the same file for other shells:
yarn ts2shell compile examples/hello.ts --target ps1 -o dist/hello.ps1
yarn ts2shell compile examples/hello.ts --target bat -o dist/hello.bat
yarn ts2shell compile examples/hello.ts --target sh -o dist/hello-posix.shimport { Env } from "std/env";
import { echo } from "std/io";
import { exec, test } from "std/shell";
Env.set("DEBUG", "1");
const flags = ["-la", "-h"];
for (const arg of flags) {
if (test("-n", arg)) {
echo("flag:", arg);
}
}
exec("ls", ...flags, "/tmp");Full docs (English) live in the Astro site:
yarn docs:devSee packages/docs for Getting started, CLI reference, target capability matrix, and error catalog.
| Target | Extension | Notes |
|---|---|---|
bash |
.sh |
Full feature set (arrays, objects, for…of) |
sh |
.sh |
POSIX subset; no object literals |
ps1 |
.ps1 |
PowerShell arrays and $env: |
bat |
.bat |
cmd.exe; limited arrays |
Details: reference/targets in the docs site.
See CONTRIBUTING.md.