From 4569705154128a643a6556d30083e9fd5fd44a89 Mon Sep 17 00:00:00 2001 From: Kare Morstol Date: Tue, 9 Sep 2014 18:52:20 +0200 Subject: [PATCH] Add example for reading file, move installation to the end. --- README.md | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b683748..2e05276 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,29 @@ A Swift module for shell scripting. -## Installation +## Usage -- In the Terminal, go to where you want to download SwiftShell. -- Run +#### Pipe several commands together - git clone https://github.com/kareman/SwiftShell.git - cd SwiftShell +```swift +#!/usr/bin/env swiftshell -- Copy/link `Div/swiftshell` to your bin folder or anywhere in your PATH. -- To install the framework, either: - - run `xcodebuild install` from the project's root folder. This will install the SwiftShell framework in ~/Library/Frameworks. - - _or_ run `xcodebuild` and copy the resulting framework from the build folder to your library folder of choice. If that is not "~/Library/Frameworks", "/Library/Frameworks" or a folder mentioned in the $DYLD_FRAMEWORK_PATH environment variable then you need to add your folder to $DYLD_FRAMEWORK_PATH. +import SwiftShell -## Examples +run("echo this is streamed") |> run("wc -w") |> standardoutput +``` + +#### Read a file line by line + +```swift +#!/usr/bin/env swiftshell + +import SwiftShell + +for line in open("../shorttext.txt").lines() { + // Do something with each line +} +``` #### Print standard input with line numbers @@ -48,16 +57,22 @@ for directory in directories { } ``` -#### Pipe several commands together +## Installation -```swift -#!/usr/bin/env swiftshell +- In the Terminal, go to where you want to download SwiftShell. +- Run -import SwiftShell + git clone https://github.com/kareman/SwiftShell.git + cd SwiftShell + +- Copy/link `Div/swiftshell` to your bin folder or anywhere in your PATH. +- To install the framework, either: + - run `xcodebuild install` from the project's root folder. This will install the SwiftShell framework in ~/Library/Frameworks. + - _or_ run `xcodebuild` and copy the resulting framework from the build folder to your library folder of choice. If that is not "~/Library/Frameworks", "/Library/Frameworks" or a folder mentioned in the $DYLD_FRAMEWORK_PATH environment variable then you need to add your folder to $DYLD_FRAMEWORK_PATH. -run("echo this is streamed") |> run("wc -w") |> standardoutput -``` ## LICENSE This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html + +If you want to use this project together with a different project with an incompatible license, send a message on GitHub and we will see what we can do.