Swiftpack.co - cobbal/swsh as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by cobbal.
cobbal/swsh v4.0.0
The Swift Shell
⭐️ 13
🕓 1 year ago
macOS linux
.package(url: "https://github.com/cobbal/swsh.git", from: "v4.0.0")

swsh

CI tests (static) CI tests (macOS) CI tests (linux) documentation coverage

A shell-scripting library for Swift, inspired by scsh.

swsh makes writing shell scripts more fun by exchanging bash (or similar) for a better thought-out language like Swift. In the process, a small amount of conciseness is traded for better quoting, error handling, and access to libraries.

Some toy examples:

import swsh

let rot13 = cmd("tr", "a-z", "n-za-m")
try! rot13.input("secret message").runString()
// -> "frperg zrffntr"

try! (rot13.input("secret") | rot13).runString()
// -> "secret"
try! (rot13 | rot13).input("secret").runString()
// -> "secret"

try! (cmd("ls") | cmd("sort", "-n")).runLines()
// -> ["1.sh", "9.sh", "10.sh"]

["hello", "world", ""].map { cmd("test", "-z", $0).runBool() }
// -> [false, false, true]

try! (cmd("false") | cmd("cat")).run()
// Fatal error: 'try!' expression unexpectedly raised an error: command "false" failed with exit code 1

Full documentation

Acknowledgements

I would like to thank the same people that scsh does.

GitHub

link
Stars: 13
Last commit: 11 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v4.0.0
1 year ago

4.0.0 (2022-07-31)

Features

  • add swift 5.5 async versions of most Command methods (0a49325)

BREAKING CHANGES

  • old synchronous versions of these methods can no longer be called in asynchronous contexts

make all test cases hide their asynchrony so linux stops crashing

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics