darrarski/swift-shell
Library for running shell scripts and other executables from swift code.
π Documentation
The library is distributed as a swift package.
// in your Package.swift, add package dependency:
.package(url: "https://github.com/darrarski/swift-shell.git", from: "0.1.0"),
// and add the library as a dependency to your target:
.product(name: "SwiftShell", package: "swift-shell"),The code is dressed in documentation comments that explain the purpose of each variable and function. The examples described below and the library unit tests explain how to use it. You can also check out the auto-generated documentation hosted on SwiftPackageIndex.
π Examples
Run bash script, send input, and retrieve the script's output:
let process = ShellProcess(.bash("IFS= read -r NAME; echo Hello, $NAME!"))
try await process.run()
try await process.send(input: "Swift\n".data(using: .utf8)!)
let output = try await process.output()!
print(String(data: output, encoding: .utf8)!) // Hello, Swift!Check out the examples included in this repository:
<details> <summary><b>Send input and stream bash script's output.</b></summary>
InputOutputExample
[SwiftShell InputOutputExample]
Run example:
$ Examples/run.sh -- InputOutputExample</details>
<details> <summary><b>Stream and decorate bash script's output.</b></summary>
DecorateOutputExample
[SwiftShell DecorateOutputExample]
Run example:
$ Examples/run.sh -- DecorateOutputExample</details>
π Development
- Use Xcode (β₯15.4).
- Clone the repository or create a fork & clone it.
- Open
SwiftShell.xcworkspacein Xcode. - Use the
SwiftShellscheme for building and testing the library. - Use other schemes to build or test examples.
- If you want to contribute, create a pull request containing your changes or bug fixes. Make sure to include tests for new/updated code.
βοΈ Do you like the project?
I would love to hear if you like my work. I can help you apply any of the solutions used in this repository in your app too! Feel free to reach out to me, or if you just want to say "thanks", you can buy me a coffee.
<a href="https://www.buymeacoffee.com/darrarski" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60" width="217" style="height: 60px !important;width: 217px !important;" ></a>
π License
Copyright Β© 2024 Dariusz Rybicki Darrarski
License: MIT
Package Metadata
Repository: darrarski/swift-shell
Stars: 6
Forks: 2
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: bash-scripting, cli, shell-scripts, swift, swift-package
README: README.md