Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
swsh
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
Acknowledgements
I would like to thank the same people that scsh does.
Github
link |
Stars: 7 |
You may find interesting
Releases
v2.0.0 - 2020-08-10T22:28:23
2.0.0 (2020-08-10)
Features
- fd duplication and more general output/error combining (1667abd)
- rework FD mapping systems (5becc68)
BREAKING CHANGES
-
Traditional, imperative file descriptor remapping has been removed in favor of a more functional mapping of what the child process will see. dup calls are now synthesized to get the right FDs in the right place.
Hopefully, this will be more composable.
Also, joinErr parameters have been removed in favor of the
combineError
property.