Swiftpack.co - Package - cobbal/swsh
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

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: 7

Used By

Total: 1

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.

v1.0.1 - 2020-07-20T14:50:09

1.0.1 (2020-07-20)

Bug Fixes

  • default kill signal should be TERM (639a7af)

v1.0.0 - 2020-07-16T20:33:27

1.0.0 (2020-07-16)

Features

BREAKING CHANGES

  • runJson has been renamed to runJSON

v0.2.0 - 2020-02-07T19:17:49

0.2.0 (2020-02-07)

Bug Fixes

  • docs not building in release (5936876)
  • make API public instead of internal (6416599)
  • release script (#9) (5387ec7)
  • report correct exit code (28ca42b)

Features

v0.1.0 - 2019-12-28T23:48:11

0.1.0 (2019-12-28)

Features