https://github.com/simonnyvall/dotcon
DotCon is a lightweight library that provides a simple and consistent interface for executing shell commands in various terminal environments...
https://github.com/simonnyvall/dotcon
bash cmd csharp nuget powershell terminal zsh
Last synced: 5 months ago
JSON representation
DotCon is a lightweight library that provides a simple and consistent interface for executing shell commands in various terminal environments...
- Host: GitHub
- URL: https://github.com/simonnyvall/dotcon
- Owner: SimonNyvall
- License: mit
- Created: 2023-05-20T13:18:40.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-24T09:38:22.000Z (over 2 years ago)
- Last Synced: 2025-02-12T06:30:54.878Z (about 1 year ago)
- Topics: bash, cmd, csharp, nuget, powershell, terminal, zsh
- Language: C#
- Homepage: https://www.nuget.org/packages/DotCon
- Size: 112 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# DotCon [](https://github.com/SimonNyvall/DotCon/actions/workflows/dotnet.yml)
DotCon is a lightweight library that provides a simple and consistent interface for executing shell commands in various terminal environments. It follows the Factory Method design pattern to create terminal instances based on different shells (Bash, Cmd, PowerShell, Zsh).
## Table of Contents
- [Features](#features)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)
## Features
- Execute shell commands synchronously and asynchronously.
- Capture the output of executed commands.
- Run script actions by parsing and executing corresponding shell commands.
- Configure terminal options such as redirecting standard output, using shell execution, and creating no window.
## Getting Started
### Prerequisites
- .NET 7.0 SDK or later
### Installation
You can add the DotCon library to your .NET project using the following methods:
#### Package Manager Console
``` bash
dotnet add package DotCon --version 8.2.0
```
Or download/ clone the project and run the RunDocker.sh file, which will start up a conatiner with the classlib added to a console application.
### Usage
#### Creating a Terminal Instance
To create a terminal instance, you can use one of the following methods:
1. Create a terminal instance using one of the available shell options.
2. Execute shell commands or run script actions using the terminal instance.
```csharp
Terminal.UseBashShell();
Terminal.UseCmdShell();
Terminal.UsePowershellShell();
Terminal.UseZshShell();
```
Or
```csharp
Terminal.UseBashShell(options =>
{
// Configure terminal options
});
```
Run terminal commands or store script to be run at a later time with the Execute methods.
```csharp
string output = terminal.Run("ls -la");
string output = await terminal.RunAsync("ls -la");
string output = terminal.ExecuteScript("myScript");
string output = await terminal.ExecuteScriptAsync("myScript");
```
Try to run commands in the terminal with a similer syntax to the TryParse
```csharp
Terminal terminal = Terminal.UseBashShell();
string output;
bool success = terminal.TryRun("ls -la", out output);
if (success)
{
// Handle successful
}
else
{
// Handle execution error
Console.WriteLine($"Error: {output}");
}
```