PsBash.Transpiler
0.10.5
dotnet add package PsBash.Transpiler --version 0.10.5
NuGet\Install-Package PsBash.Transpiler -Version 0.10.5
<PackageReference Include="PsBash.Transpiler" Version="0.10.5" />
<PackageVersion Include="PsBash.Transpiler" Version="0.10.5" />
<PackageReference Include="PsBash.Transpiler" />
paket add PsBash.Transpiler --version 0.10.5
#r "nuget: PsBash.Transpiler, 0.10.5"
#:package PsBash.Transpiler@0.10.5
#addin nuget:?package=PsBash.Transpiler&version=0.10.5
#tool nuget:?package=PsBash.Transpiler&version=0.10.5
PsBash.Transpiler
The bash → PowerShell transpiler that powers PsBash: a hand-written lexer + recursive-descent parser (AST modeled on Oils/OSH) and a PowerShell emitter. It is a leaf library with no PsBash dependencies (only Parlot), so you can embed bash-to-PowerShell translation in your own app — for example to build your own shell on top of a PowerShell runspace.
dotnet add package PsBash.Transpiler
Transpile bash to PowerShell
using PsBash.Core.Transpiler; // assembly: PsBash.Transpiler
string ps = BashTranspiler.Transpile("ls -la | grep .log | sort -k5 -rn | head -5");
// ps == "Invoke-BashLs -la | Invoke-BashGrep .log | Invoke-BashSort -k5 -rn | Invoke-BashHead -5"
Transpile accepts an optional TranspileContext (Default, or Eval for
eval-style in-process re-transpilation). Use TranspileWithMap when you need
to map a PowerShell runtime error back to the originating bash line:
TranspileResult result = BashTranspiler.TranspileWithMap("for x in a b c; do echo $x; done");
string ps = result.PowerShell; // emitted PowerShell
// result.LineMap: emitted line -> source bash line
Build your own shell
The emitted PowerShell calls Invoke-Bash* commands (e.g. Invoke-BashGrep).
To run it with full fidelity, load the ps-bash runtime module into your
runspace, then execute the transpiled text:
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using var rs = RunspaceFactory.CreateRunspace();
rs.Open();
using var ps = PowerShell.Create();
ps.Runspace = rs;
// Load the runtime: the PsBash module (Invoke-Bash* commands) ships embedded in
// the PsBash.Core package and is extracted at runtime — add a reference to
// `PsBash.Core` and import the extracted module, or `Install-Module PsBash` /
// `PsBash.Cmdlets` from the PowerShell Gallery into the runspace.
ps.AddScript("Import-Module PsBash").Invoke();
ps.Commands.Clear();
string transpiled = BashTranspiler.Transpile(userBashLine);
foreach (var item in ps.AddScript(transpiled).Invoke())
Console.WriteLine(item);
A REPL is then just: read a line → BashTranspiler.Transpile → run in the
runspace → print. Add history, completion, and prompt handling to taste. See the
ps-bash PsBash.Shell project for a complete launcher + host implementation.
Scope
- In scope: bash syntax → PowerShell text. Lexer, parser, AST (
PsBash.Core.Parser.Ast), emitter. - Out of scope (use
PsBash.Core): the runtimeInvoke-Bash*command implementations, the IPC host, and process orchestration.
License
MIT — see the repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
NuGet packages (1)
Showing the top 1 NuGet packages that depend on PsBash.Transpiler:
| Package | Downloads |
|---|---|
|
PsBash.Core
Bash-to-PowerShell transpiler library. Parses bash commands into an AST (based on Oils/OSH) and emits equivalent PowerShell. Use as a library in terminal emulators, AI agents, or any .NET app that needs bash compatibility on top of PowerShell. |
GitHub repositories
This package is not used by any popular GitHub repositories.