It's a small collection of functions to make scripting in Swift easier. (with #!/usr/bin/env swift or with swift-sh)
All of these were written kinda try!-ish while I was scripting casually, so I might fix it later.
Pass content to Swift.print() function with to: &FileHandle.standardError option.
To make this work, FileHandle type is extended to conform to TextOutputStream.
run(_ command: String, shell: String = "zsh", passthrough: Bool = false, stdInContent: String? = nil) throws -> String
Run a shell command.
shelldetermines what shell environment it should run in.passthroughdetermines if stdout of child process should also be printed out to this process.stdInContentgets piped in as standard input for the child process.
throws stderr content as an error if the command outputs to stderr.
To make this work, String type is extended to conform to Error.
I should make it not an error for the child process to print something in stderr.
Rather, I should make it throw when the process exits with non-zero code.
Run "command" and exit if the shell command fails.
Run "command" and exit if the shell command fails. Passthrough is turned on, so the main process shows the stdout of the child process.
Run "command" and throw if the shell command fails.
Run "command" and if the shell command fails, return nil.