Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taji-taji/swift-shell
Simple Shell Executor with Swift.
https://github.com/taji-taji/swift-shell
shell shell-scripts shellscript swift swift-package swift-package-manager swift5 swiftpackagemanager swiftpm
Last synced: about 1 month ago
JSON representation
Simple Shell Executor with Swift.
- Host: GitHub
- URL: https://github.com/taji-taji/swift-shell
- Owner: taji-taji
- License: mit
- Created: 2022-09-03T03:35:34.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-15T23:20:32.000Z (almost 2 years ago)
- Last Synced: 2024-03-14T15:25:44.490Z (8 months ago)
- Topics: shell, shell-scripts, shellscript, swift, swift-package, swift-package-manager, swift5, swiftpackagemanager, swiftpm
- Language: Swift
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :shell: Swift Shell
Simple shell executor with Swift.
![Test](https://github.com/taji-taji/swift-shell/actions/workflows/test.yml/badge.svg)
[![MIT License](https://img.shields.io/github/license/taji-taji/swift-shell)](https://github.com/taji-taji/swift-shell/blob/main/LICENSE)
[![Latest Version](https://img.shields.io/github/v/release/taji-taji/swift-shell?label=latest%20version)](https://github.com/taji-taji/swift-shell/releases/latest)
[![Swift Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ftaji-taji%2Fswift-shell%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/taji-taji/swift-shell)
[![Platform Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ftaji-taji%2Fswift-shell%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/taji-taji/swift-shell)## Requirements
- Swift 5.5.2 or later
## Usage
### Package.swift
To use the `SwiftShell` library in a SwiftPM project, add the following line to the dependencies in your `Package.swift` file:
```swift
.package(url: "https://github.com/taji-taji/swift-shell.git", from: "1.0.0")
```Include `"SwiftShell"` as a dependency for your executable target:
```swift
.target(name: "", dependencies: [
.product(name: "SwiftShell", package: "swift-shell"),
]),
```
Finally, add `import SwiftShell` to your source code.### Example
#### Basic Usage
```swift
import SwiftShelllet shell = Shell()
do {
// Shell is implemented with `callAsFunction`.
let output = try shell("ls", arguments: ["-l", "-a"])
print(output)
} catch {
print(error)
}
```#### Async / Await
```swift
import SwiftShelllet shell = Shell()
Task {
async let output1 = shell("brew install awesome-tool")
async let output2 = shell("bundle install")let result = try await (output1, output2)
print(result.0)
print(result.1)
}
```#### Use Environment Variables
Execute with some Environment Variables.
```swift
try shell("brew install git",
additionalEnvironment: ["HOMEBREW_NO_AUTO_UPDATE": "1"])
```