Company logo with the letters 'NotTooBad Software' TextSmith Blog

SwiftShell 3

SwiftShell  

SwiftShell 3 is finally out of beta, with a much improved readme.

So much so it may even be too long now.

Combine markdown files and convert to HTML in a Swift script.

SwiftShell  

Swift 3

Sam Burnstone recently wrote about how to convert a simple shell script to Swift. Here’s the same shell script rewritten using SwiftShell and FileSmith.

Move files to the trash with a Swift script

SwiftShell  

Swift 3

I really don’t like using the ‘rm’ shell command – one misplaced character and you can do some serious damage. But when working in the Finder I don’t think twice about deleting files, because I know I can always get them back from the trash. So here is a Swift shell script which does exactly that – it moves files to the trash instead of deleting them permanently.

The syntax is very simple – all parameters refer to file system items which should be moved to the trash:

trash file.txt a_folder
trash *.m *.h

SwiftShell 2.0 Readme

SwiftShell  

I finally got around to updating the SwiftShell 2.0 readme with some actual usage instructions:

SwiftShell: An OS X Framework for command line scripting in Swift.

How to use Swift for shell scripting

SwiftShell  

To be honest I’m not very good at shell scripting. It’s very useful for automation so I would like to be, but I just don’t like the syntax. For instance, this is how you check if a variable is greater than 100:

#!/bin/bash

if [ $var -gt 100 ]
then
    <do some stuff>
fi

Redesigning an API - Swift 2.0 style

SwiftShell  

SwiftShell (an OS X framework for shell scripting in Swift) is currently using the |> operator to combine shell commands, streams and functions, and |>> to print the results:

// SwiftShell 1

run("echo piped to the next command") |> run("wc -w") |>> standardoutput

// print out line number and content of each line in standard input
var i = 1
standardinput.lines() |> map {line in "line \(i++): \(line)\n"} |>> standardoutput

But Swift 2.0 is here, and it’s clear the way forward is protocols, method chaining and error handling. And being more explicit about what is going on. So for SwiftShell 2 I’m planning something like this:

Want to hear about new posts?