swift-shell

0.1.3

Library for running shell scripts and other executables from swift code.
darrarski/swift-shell

What's New

v0.1.3

2025-01-17T01:27:30Z

What's Changed

  • Resolve the compilation error with Swift 6.0.3 (Xcode 16.2) by @bo2themax in #3

New Contributors

Full Changelog: v0.1.2...v0.1.3

🐚 Swift Shell

Swift v5.10 platform macOS

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:

Send input and stream bash script's output.

InputOutputExample

SwiftShell InputOutputExample

Source code

Run example:

$ Examples/run.sh -- InputOutputExample

Stream and decorate bash script's output.

DecorateOutputExample

SwiftShell DecorateOutputExample

Source code

Run example:

$ Examples/run.sh -- DecorateOutputExample

🛠 Development

  • Use Xcode (≥15.4).
  • Clone the repository or create a fork & clone it.
  • Open SwiftShell.xcworkspace in Xcode.
  • Use the SwiftShell scheme 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.

Buy Me A Coffee

📄 License

Copyright © 2024 Dariusz Rybicki Darrarski

License: MIT

Description

  • Swift Tools 5.10.0
View More Packages from this Author

Dependencies

Last updated: Tue May 13 2025 03:22:27 GMT-0900 (Hawaii-Aleutian Daylight Time)