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.