Shwift
Shell-scripting in Swift
DISCLAIMER: Shwift depends on Swift’s incoming concurrency features. As such, it requires a recent Swift toolchain, and changes in the toolchain may break provided functionality without notice. This project was last seen working with the 2021-05-04 toolchain in Xcode.
Overview
Shwift aims to provide a full-featured framework for creating shell-script-like tools using Swift. We are particularly excited about the prospect of building scripts using swift-argument-parser
.
Shwift is built around two salient design points. Firstly, we want running a shell command to behave as similarly as possible to invoking a regular Swift function. For instance, we should be able to set a breakpoint on a line containing try await echo("Foo") | sed("s/Foo/Bar/")
, and stepping over this line should log Bar
to the standard out. Second we want piping between executables and native Swift code to be as low-friction as possible . Indeed, in the earlier example echo
is a builtin implemented in Swift. We also aim to offer more sophisticated builtins for interfacing with shell scripts. The first of these is process
which allows the user to process as much input as they need and return a Swift value.
We recommend looking at Sample.swift for a few examples of how this can be used.