dysh 0.1.0
dotnet add package dysh --version 0.1.0
NuGet\Install-Package dysh -Version 0.1.0
<PackageReference Include="dysh" Version="0.1.0" />
<PackageVersion Include="dysh" Version="0.1.0" />
<PackageReference Include="dysh" />
paket add dysh --version 0.1.0
#r "nuget: dysh, 0.1.0"
#:package dysh@0.1.0
#addin nuget:?package=dysh&version=0.1.0
#tool nuget:?package=dysh&version=0.1.0
dysh
Dynamic shell command execution for .NET — invoke shell commands as if they were native C# methods.
dysh is a C# library that leverages the .NET Dynamic Language Runtime (DLR) to let you execute shell commands with a fluent, natural syntax — inspired by Python's sh library. It is the spiritual successor to manojlds/cmd, rebuilt for modern .NET with async-first design and cross-platform shell abstraction.
dynamic shell = Shell.Create();
// Run a command
CommandResult result = await shell.git("status");
// Subcommands
CommandResult log = await shell.git.log(n: 10, oneline: true);
// Stream output in real time
await foreach (var line in shell.docker.logs(f: true, "my-container"))
Console.WriteLine(line);
Features
- DLR-powered syntax — any shell command becomes a C# method call via
dynamic - Async-first — all executions return
Task<CommandResult>orIAsyncEnumerable<string> - Cross-platform shell abstraction — auto-detects the appropriate shell (
bash,pwsh,cmd.exe) - Subcommand chaining —
shell.git.log()maps naturally togit log - Named argument mapping — single-char named args map to
-f, multi-char to--flag - Structured results — exit code, stdout, stderr, and elapsed time in one object
- CancellationToken support — full async cancellation throughout
- Scoped execution — set working directory and environment variables per instance
Installation
dotnet add package dysh
Getting Started
Basic usage
using Dysh;
dynamic shell = Shell.Create();
CommandResult result = await shell.git("status");
if (result.Success)
Console.WriteLine(result.StandardOutput);
else
Console.WriteLine(result.StandardError);
Subcommands
// Equivalent to: git log --oneline -n 10
CommandResult log = await shell.git.log(n: 10, oneline: true);
Argument mapping
// Positional args → passed as-is
await shell.ls("/home/user");
// Single-char named arg → -v
await shell.tar(x: true, z: true, f: "archive.tar.gz");
// → tar -x -z -f archive.tar.gz
// Multi-char named arg → --output
await shell.ffmpeg(input: "video.mp4", output: "out.mp4");
// → ffmpeg --input video.mp4 --output out.mp4
Streaming output
// Stream stdout line by line as it's produced
await foreach (var line in shell.ping("8.8.8.8", c: 4))
Console.WriteLine(line);
Scoped shell with options
dynamic scoped = Shell.Create(options => options
.WithWorkingDirectory("/var/app")
.WithEnvironmentVariable("NODE_ENV", "production")
.WithShell(ShellKind.Bash));
await scoped.npm("install");
await scoped.npm.run("build");
Error handling
// Check manually
var result = await shell.git("push");
if (!result.Success)
Console.Error.WriteLine($"Exit {result.ExitCode}: {result.StandardError}");
// Or throw on failure
await shell.git("push").EnsureSuccess();
Shell Support
| Shell | Identifier | Platform |
|---|---|---|
| Auto-detect | ShellKind.Native (default) |
Cross-platform |
| Bash | ShellKind.Bash |
Linux / macOS |
| sh | ShellKind.Sh |
Linux / macOS |
| PowerShell | ShellKind.Pwsh |
Cross-platform |
| cmd.exe | ShellKind.Cmd |
Windows |
The default Native adapter resolves to bash on Linux/macOS and cmd.exe on Windows. You can always override this explicitly via ShellOptions.
How it works
dysh implements DynamicObject and overrides TryInvokeMember and TryGetMember to intercept method calls at runtime via the DLR. Each call is translated into a CommandDescriptor — a structured representation of the executable, subcommands, arguments, and environment — which is then handed off to an IShellAdapter for execution via System.Diagnostics.Process.
dynamic shell.git.log(n: 10)
│
▼
TryGetMember("git") → SubcommandProxy("git")
│
▼
TryInvokeMember("log") → CommandDescriptor { Executable="git", Subcommand="log", Args=["-n","10"] }
│
▼
IShellAdapter.ExecuteAsync(descriptor)
│
▼
ProcessRunner → System.Diagnostics.Process
│
▼
CommandResult { ExitCode, StandardOutput, StandardError, Elapsed }
Acknowledgements
dysh is the spiritual successor to manojlds/cmd and draws inspiration from Python's sh. The original cmd library was a creative showcase of the C# DLR — dysh aims to carry that spirit forward as a maintained, production-grade library.
License
MIT © dysh contributors
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 is compatible. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.0)
- Microsoft.CSharp (>= 4.7.0)
-
net9.0
- Microsoft.CSharp (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 92 | 5/8/2026 |
### Fixed
• Update github actions to correctly import the necessary secrets to publish packages
Full changelog at https://github.com/chrisbewz/dysh/blob/refs/tags/v0.2.0/CHANGELOG.md