Extensions
+The following extensions are available globally.
+ +-
+
-
+ ++
+ + + FileHandle +++ +++ + +++Undocumented
+ + See more +
+
diff --git a/Extensions.html b/Extensions.html new file mode 100644 index 0000000..24f20d8 --- /dev/null +++ b/Extensions.html @@ -0,0 +1,247 @@ + + +
+Docs (64% documented)
+ +The following extensions are available globally.
+ +
+
+
+ FileHandle
+
+ Undocumented
+ + See more +Docs (64% documented)
+ +Undocumented
+ +
+
+
+ readSome()
+
+ Undocumented
+ +
+
+
+ read()
+
+ Undocumented
+ +
+
+
+ lines()
+
+ Undocumented
+ +
+
+
+ writeTo(_:)
+
+ Undocumented
+ +
+
+
+ write(_:)
+
+ Undocumented
+ +
+
+
+ writeln(_:)
+
+ Undocumented
+ +
+
+
+ writeln()
+
+ Undocumented
+ +
+
+
+ closeStream()
+
+ Undocumented
+ +Docs (64% documented)
+ +
+
+
+ replace(_:_:)
+
+ Undocumented
+ +
+
+
+ replace(_:_:limit:)
+
+ Replace the first limit occurrences of oldString with newString.
Swift
+public func replace (oldString: String, _ newString: String, limit: Int) -> String
+
+
+
+
+ split(_:)
+
+ Undocumented
+ +
+
+
+ trim()
+
+ Undocumented
+ +
+
+
+ countOccurrencesOf(_:)
+
+ Undocumented
+ +
+
+
+ findAll(_:)
+
+ A lazy sequence of the ranges of findstring in this string.
Swift
+public func findAll (findstring: String) -> SequenceOf<Range<String.Index>>
+
+
+
+
+ partition(_:)
+
+ Split the string at the first occurrence of separator, and return a 3-tuple containing the part +before the separator, the separator itself, and the part after the separator. If the separator is +not found, return a 3-tuple containing the string itself, followed by two empty strings.
+ +Swift
+public func partition (separator: String) -> (String, String, String)
+
+ Docs (64% documented)
+ +The following functions are available globally.
+ +
+
+
+ |>(_:_:)
+
+ Undocumented
+ +
+
+
+ filter(_:)
+
+ Lazily return a sequence containing the elements of source, in order, that satisfy the predicate includeElement
+ +Swift
+public func filter <S : SequenceType>
+ (includeElement: (S.Generator.Element) -> Bool)
+ (source: S)
+ -> LazySequence<FilterSequenceView<S>>
+
+
+
+
+ sorted(_:)
+
+ Return an Array containing the sorted elements of source according to ‘isOrderedBefore’.
Requires: isOrderedBefore is a strict weak ordering
+<http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings> over elements.
Swift
+public func sorted <S : SequenceType>
+ (isOrderedBefore: (S.Generator.Element, S.Generator.Element) -> Bool)
+ (source: S)
+ -> [S.Generator.Element]
+
+
+
+
+ map(_:)
+
+ Lazily return a sequence containing the results of mapping transform over source.
+ +Swift
+public func map <S: SequenceType, T>
+ (transform: (S.Generator.Element) -> T)
+ (source: S)
+ -> LazySequence<MapSequenceView<S, T>>
+
+
+
+
+ reduce(_:_:)
+
+ Return the result of repeatedly calling combine with an accumulated value +initialized to initial and each element of sequence, in turn.
+ +Swift
+public func reduce <S : SequenceType, U>
+ (initial: U, combine: (U, S.Generator.Element) -> U)
+ (sequence: S)
+ -> U
+
+
+
+
+ split(_:)
+
+ Split text over delimiter, returning an array.
+ +Swift
+public func split (_ delimiter: String = "\n")(text: String) -> [String]
+
+
+
+
+ join(_:)
+
+ Insert separator between each item in elements.
+ +Swift
+public func join <C : ExtensibleCollectionType, S : SequenceType where S.Generator.Element == C>
+ (separator: C)
+ (elements: S)
+ -> C
+
+
+
+
+ toArray(_:)
+
+ Turn a sequence into an array. For use after the |> operator.
+ +Swift
+public func toArray <S : SequenceType> (sequence: S) -> [S.Generator.Element]
+
+
+
+
+ drop(_:)
+
+ Discard all elements in tobedropped from sequence.
Swift
+public func drop <S : SequenceType, T : Equatable where S.Generator.Element == T>
+ (tobedropped: [T])
+ (sequence: S)
+ -> LazySequence<FilterSequenceView<S>>
+
+
+
+
+ take(_:)
+
+ Return at most the first numbertotake elements of sequence
Swift
+public func take <S : SequenceType, T where S.Generator.Element == T>
+ (numbertotake: Int)(sequence: S) -> [T]
+
+
+
+
+ printErrorAndExit(_:)
+
+ Print message to standard error and halt execution.
+ +Swift
+@noreturn public func printErrorAndExit (errormessage: String)
+
+
+
+
+ open(_:)
+
+ Open a file for reading, and exit if an error occurs.
+ +Swift
+public func open (path: String) -> ReadableStreamType
+
+
+
+
+ open(forWriting:overwrite:)
+
+ Open a file for writing, create it if it doesn’t exist, and exit if an error occurs. +If the file already exists and overwrite=false, the writing will begin at the end of the file.
+ +Swift
+public func open (forWriting path: String, overwrite: Bool = false) -> WriteableStreamType
+
+
+
+ overwrite
+
+ |
+
+
+
+ If true, replace the file if it exists. + + |
+
+
+
+ stream(_:)
+
+ Create a stream from a String.
+ +Swift
+public func stream (text: String) -> ReadableStreamType
+
+
+
+
+ stream(_:)
+
+ Create a stream from a function returning a generator function, which is called every time the stream is asked for more text.
+ +stream { + // initialisation… + return { + // called repeatedly by the resulting stream + // return text, or return nil when done. + } +}
+ +Swift
+public func stream ( closure:() -> () -> String? ) -> ReadableStreamType
+
+ The output stream.
+ +
+
+
+ stream(_:)
+
+ Create a stream from a sequence of Strings.
+ +Swift
+public func stream <Seq : SequenceType where Seq.Generator.Element == String> (sequence: Seq) -> ReadableStreamType
+
+
+
+
+ streams()
+
+ Return a writable stream and a readable stream. What you write to the 1st one can be read from the 2nd one. +Make sure to call closeStream() on the writable stream before you call read() on the readable one.
+ +Swift
+public func streams () -> (WriteableStreamType, ReadableStreamType)
+
+
+
+
+ split(delimiter:)
+
+ Split a stream lazily
+ +Swift
+public func split (delimiter: String = "\n")(stream: ReadableStreamType) -> SequenceOf<String>
+
+
+
+
+ writeTo(_:)
+
+ Write something to a stream.
+ +something |> writeTo(writablestream)
+
+
+ Swift
+public func writeTo <T> (stream: WriteableStreamType)(input: T)
+
+
+
+
+ writeTo(_:)
+
+ Write a String to a writable stream.
+ +Swift
+public func writeTo (stream: WriteableStreamType)(input: String)
+
+
+
+
+ writeTo(_:)
+
+ Write a sequence to a stream.
+ +Swift
+public func writeTo <S : SequenceType> (stream: WriteableStreamType)(seq: S)
+
+
+
+
+ |>>(_:_:)
+
+ Write something to a stream.
+ +something |>> writablestream
+ +Swift
+public func |>> <T> (input: T, stream: WriteableStreamType)
+
+
+
+
+ |>>(_:_:)
+
+ Write a String to a writable stream.
+ +Swift
+public func |>> (text: String, stream: WriteableStreamType)
+
+
+
+
+ |>>(_:_:)
+
+ Write a sequence to a stream.
+ +Swift
+public func |>> <S : SequenceType> (seq: S, stream: WriteableStreamType)
+
+
+
+
+ |>(_:_:)
+
+ Specific handling of func run (shellcommand: String) -> ReadableStreamType on the right side using the stream on the +left side as standard input.
+ +Warning: is only meant to be used with the run
command, but could also unintentionally catch other uses of
+ReadableStreamType |> ReadableStreamType
, though that statement doesn’t make any sense.
Swift
+public func |> (lhs: ReadableStreamType, @autoclosure rhs: () -> ReadableStreamType) -> ReadableStreamType
+
+
+
+
+ run(_:)
+
+ Run a shell command synchronously with no standard input,
+or if to the right of a ReadableStreamType |>
, use the stream on the left side as standard input.
Swift
+public func run (shellcommand: String) -> ReadableStreamType
+
+ Standard output
+ +
+
+
+ $(_:)
+
+ Shortcut for in-line command, returns output as String.
+ +Swift
+public func $ (shellcommand: String) -> String
+
+
+
+
+ parameters(_:)
+
+ Turn a sequence into valid parameters for a shell command, properly quoted
+ +Swift
+public func parameters <S : SequenceType> (sequence: S) -> String
+
+
+
+
+ /(_:_:)
+
+ Allows for "/directory" / "file.extension" etc.
Swift
+public func / (leftpath: String, rightpath: String) -> String
+
+ Docs (64% documented)
+ +The following global variables are available globally.
+ +
+
+
+ environment
+
+ Undocumented
+ +
+
+
+ standardinput
+
+ Undocumented
+ +
+
+
+ standardoutput
+
+ Undocumented
+ +
+
+
+ standarderror
+
+ Undocumented
+ +
+
+
+ streamencoding
+
+ Undocumented
+ +
+
+
+ File
+
+ The default NSFileManager
+ +Swift
+public let File = NSFileManager.defaultManager()
+
+
+
+
+ tempdirectory
+
+ The tempdirectory is unique each time a script is run and is created the first time it is used. +It lies in the user’s temporary directory and will be automatically deleted at some point.
+ +Swift
+public let tempdirectory: String =
+
+
+
+
+ workdirectory
+
+ The current working directory.
+ +Must be used instead of run("cd ...") because all the run commands are executed in a
+separate process and changing the directory there will not affect the rest of the Swift script.
This directory is also used as the base for relative URL’s.
+ +Swift
+public var workdirectory: String
+
+ Docs (64% documented)
+ +The following protocols are available globally.
+ +
+
+
+ ReadableStreamType
+
+ A stream of text. Does as much as possible lazily.
+ + See more +Swift
+public protocol ReadableStreamType : Streamable
+
+
+
+
+ WriteableStreamType
+
+ An output stream, like standard output and standard error.
+ + See more +Swift
+public protocol WriteableStreamType : OutputStreamType
+
+ Docs (64% documented)
+ +A stream of text. Does as much as possible lazily.
+ +
+
+
+ readSome()
+
+ Whatever amount of text the stream feels like providing. +If the source is a file this will read everything at once.
+ +Swift
+func readSome () -> String?
+
+ more text from the stream, or nil if we have reached the end.
+ +
+
+
+ read()
+
+ Read everything at once.
+ +Swift
+func read () -> String
+
+
+
+
+ lines()
+
+ Lazily split the stream into lines.
+ +Swift
+func lines () -> SequenceOf<String>
+
+
+
+
+ writeTo(_:)
+
+ Enable stream to be used by println
and toString
.
Swift
+func writeTo <Target : OutputStreamType> (inout target: Target)
+
+ Docs (64% documented)
+ +An output stream, like standard output and standard error.
+ +
+
+
+ write(_:)
+
+ Undocumented
+ +
+
+
+ writeln(_:)
+
+ Undocumented
+ +
+
+
+ writeln()
+
+ Undocumented
+ +
+
+
+ closeStream()
+
+ Must be called on local streams when finished writing.
+ +Swift
+func closeStream ()
+
+ Docs (64% documented)
+ +The following extensions are available globally.
+ +
+
+
+ FileHandle
+
+ Undocumented
+ + See more +Docs (64% documented)
+ +Undocumented
+ +
+
+
+ readSome()
+
+ Undocumented
+ +
+
+
+ read()
+
+ Undocumented
+ +
+
+
+ lines()
+
+ Undocumented
+ +
+
+
+ writeTo(_:)
+
+ Undocumented
+ +
+
+
+ write(_:)
+
+ Undocumented
+ +
+
+
+ writeln(_:)
+
+ Undocumented
+ +
+
+
+ writeln()
+
+ Undocumented
+ +
+
+
+ closeStream()
+
+ Undocumented
+ +Docs (64% documented)
+ +
+
+
+ replace(_:_:)
+
+ Undocumented
+ +
+
+
+ replace(_:_:limit:)
+
+ Replace the first limit occurrences of oldString with newString.
Swift
+public func replace (oldString: String, _ newString: String, limit: Int) -> String
+
+
+
+
+ split(_:)
+
+ Undocumented
+ +
+
+
+ trim()
+
+ Undocumented
+ +
+
+
+ countOccurrencesOf(_:)
+
+ Undocumented
+ +
+
+
+ findAll(_:)
+
+ A lazy sequence of the ranges of findstring in this string.
Swift
+public func findAll (findstring: String) -> SequenceOf<Range<String.Index>>
+
+
+
+
+ partition(_:)
+
+ Split the string at the first occurrence of separator, and return a 3-tuple containing the part +before the separator, the separator itself, and the part after the separator. If the separator is +not found, return a 3-tuple containing the string itself, followed by two empty strings.
+ +Swift
+public func partition (separator: String) -> (String, String, String)
+
+ Docs (64% documented)
+ +The following functions are available globally.
+ +
+
+
+ |>(_:_:)
+
+ Undocumented
+ +
+
+
+ filter(_:)
+
+ Lazily return a sequence containing the elements of source, in order, that satisfy the predicate includeElement
+ +Swift
+public func filter <S : SequenceType>
+ (includeElement: (S.Generator.Element) -> Bool)
+ (source: S)
+ -> LazySequence<FilterSequenceView<S>>
+
+
+
+
+ sorted(_:)
+
+ Return an Array containing the sorted elements of source according to ‘isOrderedBefore’.
Requires: isOrderedBefore is a strict weak ordering
+<http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings> over elements.
Swift
+public func sorted <S : SequenceType>
+ (isOrderedBefore: (S.Generator.Element, S.Generator.Element) -> Bool)
+ (source: S)
+ -> [S.Generator.Element]
+
+
+
+
+ map(_:)
+
+ Lazily return a sequence containing the results of mapping transform over source.
+ +Swift
+public func map <S: SequenceType, T>
+ (transform: (S.Generator.Element) -> T)
+ (source: S)
+ -> LazySequence<MapSequenceView<S, T>>
+
+
+
+
+ reduce(_:_:)
+
+ Return the result of repeatedly calling combine with an accumulated value +initialized to initial and each element of sequence, in turn.
+ +Swift
+public func reduce <S : SequenceType, U>
+ (initial: U, combine: (U, S.Generator.Element) -> U)
+ (sequence: S)
+ -> U
+
+
+
+
+ split(_:)
+
+ Split text over delimiter, returning an array.
+ +Swift
+public func split (_ delimiter: String = "\n")(text: String) -> [String]
+
+
+
+
+ join(_:)
+
+ Insert separator between each item in elements.
+ +Swift
+public func join <C : ExtensibleCollectionType, S : SequenceType where S.Generator.Element == C>
+ (separator: C)
+ (elements: S)
+ -> C
+
+
+
+
+ toArray(_:)
+
+ Turn a sequence into an array. For use after the |> operator.
+ +Swift
+public func toArray <S : SequenceType> (sequence: S) -> [S.Generator.Element]
+
+
+
+
+ drop(_:)
+
+ Discard all elements in tobedropped from sequence.
Swift
+public func drop <S : SequenceType, T : Equatable where S.Generator.Element == T>
+ (tobedropped: [T])
+ (sequence: S)
+ -> LazySequence<FilterSequenceView<S>>
+
+
+
+
+ take(_:)
+
+ Return at most the first numbertotake elements of sequence
Swift
+public func take <S : SequenceType, T where S.Generator.Element == T>
+ (numbertotake: Int)(sequence: S) -> [T]
+
+
+
+
+ printErrorAndExit(_:)
+
+ Print message to standard error and halt execution.
+ +Swift
+@noreturn public func printErrorAndExit (errormessage: String)
+
+
+
+
+ open(_:)
+
+ Open a file for reading, and exit if an error occurs.
+ +Swift
+public func open (path: String) -> ReadableStreamType
+
+
+
+
+ open(forWriting:overwrite:)
+
+ Open a file for writing, create it if it doesn’t exist, and exit if an error occurs. +If the file already exists and overwrite=false, the writing will begin at the end of the file.
+ +Swift
+public func open (forWriting path: String, overwrite: Bool = false) -> WriteableStreamType
+
+
+
+ overwrite
+
+ |
+
+
+
+ If true, replace the file if it exists. + + |
+
+
+
+ stream(_:)
+
+ Create a stream from a String.
+ +Swift
+public func stream (text: String) -> ReadableStreamType
+
+
+
+
+ stream(_:)
+
+ Create a stream from a function returning a generator function, which is called every time the stream is asked for more text.
+ +stream { + // initialisation… + return { + // called repeatedly by the resulting stream + // return text, or return nil when done. + } +}
+ +Swift
+public func stream ( closure:() -> () -> String? ) -> ReadableStreamType
+
+ The output stream.
+ +
+
+
+ stream(_:)
+
+ Create a stream from a sequence of Strings.
+ +Swift
+public func stream <Seq : SequenceType where Seq.Generator.Element == String> (sequence: Seq) -> ReadableStreamType
+
+
+
+
+ streams()
+
+ Return a writable stream and a readable stream. What you write to the 1st one can be read from the 2nd one. +Make sure to call closeStream() on the writable stream before you call read() on the readable one.
+ +Swift
+public func streams () -> (WriteableStreamType, ReadableStreamType)
+
+
+
+
+ split(delimiter:)
+
+ Split a stream lazily
+ +Swift
+public func split (delimiter: String = "\n")(stream: ReadableStreamType) -> SequenceOf<String>
+
+
+
+
+ writeTo(_:)
+
+ Write something to a stream.
+ +something |> writeTo(writablestream)
+
+
+ Swift
+public func writeTo <T> (stream: WriteableStreamType)(input: T)
+
+
+
+
+ writeTo(_:)
+
+ Write a String to a writable stream.
+ +Swift
+public func writeTo (stream: WriteableStreamType)(input: String)
+
+
+
+
+ writeTo(_:)
+
+ Write a sequence to a stream.
+ +Swift
+public func writeTo <S : SequenceType> (stream: WriteableStreamType)(seq: S)
+
+
+
+
+ |>>(_:_:)
+
+ Write something to a stream.
+ +something |>> writablestream
+ +Swift
+public func |>> <T> (input: T, stream: WriteableStreamType)
+
+
+
+
+ |>>(_:_:)
+
+ Write a String to a writable stream.
+ +Swift
+public func |>> (text: String, stream: WriteableStreamType)
+
+
+
+
+ |>>(_:_:)
+
+ Write a sequence to a stream.
+ +Swift
+public func |>> <S : SequenceType> (seq: S, stream: WriteableStreamType)
+
+
+
+
+ |>(_:_:)
+
+ Specific handling of func run (shellcommand: String) -> ReadableStreamType on the right side using the stream on the +left side as standard input.
+ +Warning: is only meant to be used with the run
command, but could also unintentionally catch other uses of
+ReadableStreamType |> ReadableStreamType
, though that statement doesn’t make any sense.
Swift
+public func |> (lhs: ReadableStreamType, @autoclosure rhs: () -> ReadableStreamType) -> ReadableStreamType
+
+
+
+
+ run(_:)
+
+ Run a shell command synchronously with no standard input,
+or if to the right of a ReadableStreamType |>
, use the stream on the left side as standard input.
Swift
+public func run (shellcommand: String) -> ReadableStreamType
+
+ Standard output
+ +
+
+
+ $(_:)
+
+ Shortcut for in-line command, returns output as String.
+ +Swift
+public func $ (shellcommand: String) -> String
+
+
+
+
+ parameters(_:)
+
+ Turn a sequence into valid parameters for a shell command, properly quoted
+ +Swift
+public func parameters <S : SequenceType> (sequence: S) -> String
+
+
+
+
+ /(_:_:)
+
+ Allows for "/directory" / "file.extension" etc.
Swift
+public func / (leftpath: String, rightpath: String) -> String
+
+ Docs (64% documented)
+ +The following global variables are available globally.
+ +
+
+
+ environment
+
+ Undocumented
+ +
+
+
+ standardinput
+
+ Undocumented
+ +
+
+
+ standardoutput
+
+ Undocumented
+ +
+
+
+ standarderror
+
+ Undocumented
+ +
+
+
+ streamencoding
+
+ Undocumented
+ +
+
+
+ File
+
+ The default NSFileManager
+ +Swift
+public let File = NSFileManager.defaultManager()
+
+
+
+
+ tempdirectory
+
+ The tempdirectory is unique each time a script is run and is created the first time it is used. +It lies in the user’s temporary directory and will be automatically deleted at some point.
+ +Swift
+public let tempdirectory: String =
+
+
+
+
+ workdirectory
+
+ The current working directory.
+ +Must be used instead of run("cd ...") because all the run commands are executed in a
+separate process and changing the directory there will not affect the rest of the Swift script.
This directory is also used as the base for relative URL’s.
+ +Swift
+public var workdirectory: String
+
+ Docs (64% documented)
+ +The following protocols are available globally.
+ +
+
+
+ ReadableStreamType
+
+ A stream of text. Does as much as possible lazily.
+ + See more +Swift
+public protocol ReadableStreamType : Streamable
+
+
+
+
+ WriteableStreamType
+
+ An output stream, like standard output and standard error.
+ + See more +Swift
+public protocol WriteableStreamType : OutputStreamType
+
+ Docs (64% documented)
+ +A stream of text. Does as much as possible lazily.
+ +
+
+
+ readSome()
+
+ Whatever amount of text the stream feels like providing. +If the source is a file this will read everything at once.
+ +Swift
+func readSome () -> String?
+
+ more text from the stream, or nil if we have reached the end.
+ +
+
+
+ read()
+
+ Read everything at once.
+ +Swift
+func read () -> String
+
+
+
+
+ lines()
+
+ Lazily split the stream into lines.
+ +Swift
+func lines () -> SequenceOf<String>
+
+
+
+
+ writeTo(_:)
+
+ Enable stream to be used by println
and toString
.
Swift
+func writeTo <Target : OutputStreamType> (inout target: Target)
+
+ Docs (64% documented)
+ +An output stream, like standard output and standard error.
+ +
+
+
+ write(_:)
+
+ Undocumented
+ +
+
+
+ writeln(_:)
+
+ Undocumented
+ +
+
+
+ writeln()
+
+ Undocumented
+ +
+
+
+ closeStream()
+
+ Must be called on local streams when finished writing.
+ +Swift
+func closeStream ()
+
+ Docs (64% documented)
+ +Updated to Swift 1.2 (Xcode 6.3). Use this for earlier versions of Swift (Xcode 6.1.1 and 6.2).
+An OS X Framework for command line scripting in Swift. It supports joining together shell commands and Swift functions, like the pipe in shell commands and the pipe forward operator in F#.
+Shell commands return readable streams, which can be read all at once with read()
or read lazily (as in piece by piece) with readSome()
. The latter is useful for long texts.
#!/usr/bin/env swiftshell
+
+import SwiftShell
+
+let result = run("some shell command").read()
+
+
+Commands can be piped together:
+run("echo piped to the next command") |> run("wc -w") |>> standardoutput
+
+
+Use any sequence as parameters for a command:
+run( "chmod +x" + parameters(files) )
+
+
+For in-line commands, use $("command"):
print( "The time and date is " + $("date -u") )
+
+Files are streams too. They can be read line by line:
+for line in open("file1.txt").lines() {
+ // Do something with each line
+}
+
+
+Or written to:
+let file2 = open(forWriting: tempdirectory / "newfile.txt" )
+run("echo line 1") |>> file2
+file2.writeln("line 2")
+
+
+And there’s easy access to NSFileManager:
+if File.fileExistsAtPath("fileiwant.txt") {...}
+if File.isExecutableFileAtPath("program") {...}
+...
+
+is also a stream:
+var i = 1
+for line in standardinput.lines() {
+ print("line \(i++): ")
+ println(line)
+}
+
+
+or
+var i = 1
+standardinput.lines() |> map {line in "line \(i++): \(line)\n"} |>> standardoutput
+
+
+Launch with e.g. ls | print_linenumbers.swift
Run
+git clone https://github.com/kareman/SwiftShell.git
+cd SwiftShell
+Copy/link Misc/swiftshell to your bin folder or anywhere in your PATH.
To install the framework itself, either:
+ +xcodebuild install from the project’s root folder. This will install the SwiftShell framework in ~/Library/Frameworks.xcodebuild and copy the resulting framework from the build folder to your library folder of choice. If that is not ~/Library/Frameworks,
/Library/Frameworksor a folder mentioned in the $DYLD_FRAMEWORK_PATH environment variable then you need to add your folder to $DYLD_FRAMEWORK_PATH.
Released under the MIT License (MIT), http://opensource.org/licenses/MIT
+ +Some files are covered by other licences, see included works.
+ +Kåre Morstøl, NotTooBad Software
+ +| t |
Docs (64% documented)
+ +Updated to Swift 1.2 (Xcode 6.3). Use this for earlier versions of Swift (Xcode 6.1.1 and 6.2).
+An OS X Framework for command line scripting in Swift. It supports joining together shell commands and Swift functions, like the pipe in shell commands and the pipe forward operator in F#.
+Shell commands return readable streams, which can be read all at once with read()
or read lazily (as in piece by piece) with readSome()
. The latter is useful for long texts.
#!/usr/bin/env swiftshell
+
+import SwiftShell
+
+let result = run("some shell command").read()
+
+
+Commands can be piped together:
+run("echo piped to the next command") |> run("wc -w") |>> standardoutput
+
+
+Use any sequence as parameters for a command:
+run( "chmod +x" + parameters(files) )
+
+
+For in-line commands, use $("command"):
print( "The time and date is " + $("date -u") )
+
+Files are streams too. They can be read line by line:
+for line in open("file1.txt").lines() {
+ // Do something with each line
+}
+
+
+Or written to:
+let file2 = open(forWriting: tempdirectory / "newfile.txt" )
+run("echo line 1") |>> file2
+file2.writeln("line 2")
+
+
+And there’s easy access to NSFileManager:
+if File.fileExistsAtPath("fileiwant.txt") {...}
+if File.isExecutableFileAtPath("program") {...}
+...
+
+is also a stream:
+var i = 1
+for line in standardinput.lines() {
+ print("line \(i++): ")
+ println(line)
+}
+
+
+or
+var i = 1
+standardinput.lines() |> map {line in "line \(i++): \(line)\n"} |>> standardoutput
+
+
+Launch with e.g. ls | print_linenumbers.swift
Run
+git clone https://github.com/kareman/SwiftShell.git
+cd SwiftShell
+Copy/link Misc/swiftshell to your bin folder or anywhere in your PATH.
To install the framework itself, either:
+ +xcodebuild install from the project’s root folder. This will install the SwiftShell framework in ~/Library/Frameworks.xcodebuild and copy the resulting framework from the build folder to your library folder of choice. If that is not ~/Library/Frameworks,
/Library/Frameworksor a folder mentioned in the $DYLD_FRAMEWORK_PATH environment variable then you need to add your folder to $DYLD_FRAMEWORK_PATH.
Released under the MIT License (MIT), http://opensource.org/licenses/MIT
+ +Some files are covered by other licences, see included works.
+ +Kåre Morstøl, NotTooBad Software
+ +| t |