Skip to content
This repository was archived by the owner on Jul 18, 2018. It is now read-only.

Commit eb2cad3

Browse files
hooman96JustinJiaDev
authored andcommitted
Add folding argument to pwd()
1 parent 5e0ffb1 commit eb2cad3

9 files changed

Lines changed: 39 additions & 12 deletions

File tree

SwiftShell.playground/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
import SwiftShell
1010

11-
echo("Hello, SwiftShell!")
11+
echo("Hello, SwiftShell!")

SwiftShell.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
D078FC551D2CBE6A00706A2F /* Print.swift in Sources */ = {isa = PBXBuildFile; fileRef = D078FC541D2CBE6A00706A2F /* Print.swift */; };
1313
D0997B651CC1C4B800D9BC6A /* List.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0997B641CC1C4B800D9BC6A /* List.swift */; };
1414
D0997B671CC1C4CC00D9BC6A /* Run.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0997B661CC1C4CC00D9BC6A /* Run.swift */; };
15-
D0997B691CC1CAC300D9BC6A /* OpenDirectory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0997B681CC1CAC300D9BC6A /* OpenDirectory.swift */; };
15+
D0997B691CC1CAC300D9BC6A /* ChangeDirectory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0997B681CC1CAC300D9BC6A /* ChangeDirectory.swift */; };
1616
D0997B6B1CC1CB8200D9BC6A /* PrintWorkingDirectory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0997B6A1CC1CB8200D9BC6A /* PrintWorkingDirectory.swift */; };
1717
D0997B6D1CC1CBCD00D9BC6A /* Echo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0997B6C1CC1CBCD00D9BC6A /* Echo.swift */; };
1818
D0ACE6831CF1317000DA5F2C /* Pipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0ACE6821CF1317000DA5F2C /* Pipe.swift */; };
@@ -41,7 +41,7 @@
4141
D078FC541D2CBE6A00706A2F /* Print.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Print.swift; sourceTree = "<group>"; };
4242
D0997B641CC1C4B800D9BC6A /* List.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = List.swift; sourceTree = "<group>"; };
4343
D0997B661CC1C4CC00D9BC6A /* Run.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Run.swift; sourceTree = "<group>"; };
44-
D0997B681CC1CAC300D9BC6A /* OpenDirectory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenDirectory.swift; sourceTree = "<group>"; };
44+
D0997B681CC1CAC300D9BC6A /* ChangeDirectory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeDirectory.swift; sourceTree = "<group>"; };
4545
D0997B6A1CC1CB8200D9BC6A /* PrintWorkingDirectory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintWorkingDirectory.swift; sourceTree = "<group>"; };
4646
D0997B6C1CC1CBCD00D9BC6A /* Echo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Echo.swift; sourceTree = "<group>"; };
4747
D0ACE6821CF1317000DA5F2C /* Pipe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pipe.swift; sourceTree = "<group>"; };
@@ -110,7 +110,7 @@
110110
D078FC4D1D2CB20300706A2F /* Command */ = {
111111
isa = PBXGroup;
112112
children = (
113-
D0997B681CC1CAC300D9BC6A /* OpenDirectory.swift */,
113+
D0997B681CC1CAC300D9BC6A /* ChangeDirectory.swift */,
114114
D0997B6A1CC1CB8200D9BC6A /* PrintWorkingDirectory.swift */,
115115
D0997B661CC1C4CC00D9BC6A /* Run.swift */,
116116
);
@@ -271,7 +271,7 @@
271271
D0ACE6831CF1317000DA5F2C /* Pipe.swift in Sources */,
272272
D0997B651CC1C4B800D9BC6A /* List.swift in Sources */,
273273
D0997B6B1CC1CB8200D9BC6A /* PrintWorkingDirectory.swift in Sources */,
274-
D0997B691CC1CAC300D9BC6A /* OpenDirectory.swift in Sources */,
274+
D0997B691CC1CAC300D9BC6A /* ChangeDirectory.swift in Sources */,
275275
D0997B6D1CC1CBCD00D9BC6A /* Echo.swift in Sources */,
276276
D0ACE6871CF13D1F00DA5F2C /* Git.swift in Sources */,
277277
D078FC551D2CBE6A00706A2F /* Print.swift in Sources */,

SwiftShell.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// OpenDirectory.swift
2+
// ChangeDirectory.swift
33
// SwiftShell
44
//
55
// Created by Justin Jia on 4/15/16.

SwiftShell/Git.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum GitCommand: String {
1717
case checkout = "checkout"
1818
case branch = "branch"
1919
case rebase = "rebase"
20+
case log = "log"
2021

2122
}
2223

@@ -47,5 +48,12 @@ public enum Git {
4748
public static func commit(_ message: String, options: CommitOption...) -> String {
4849
return git(command: .commit, arguments: ["-m", message] + options.map { $0.rawValue })
4950
}
50-
51+
52+
public enum CheckOutOption: String {
53+
case create = "-b"
54+
}
55+
56+
public static func log() -> String {
57+
return git(command: .log)
58+
}
5159
}

SwiftShell/PrintWorkingDirectory.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88

99
import Foundation
1010

11-
public func pwd() -> String {
11+
let foldingLimit:Int = 15
12+
13+
public func pwd(folding: Bool = false) -> String {
1214
print(command: "pwd")
1315
var buffer: [Int8] = Array(repeating: 0, count: Int(PATH_MAX))
1416
getcwd(&buffer, buffer.count)
15-
let output = String(cString: buffer) ?? ""
17+
var output = String(cString: buffer) ?? ""
18+
19+
let pathComponents = output.characters.split{ $0 == "/" }.map(String.init)
20+
21+
if let firstPathComponents = pathComponents.first, let lastPathComponents = pathComponents.last, folding == true, output.characters.count > foldingLimit {
22+
output = firstPathComponents + "/.../" + lastPathComponents
23+
}
24+
1625
print(output)
1726
return output
1827
}

SwiftShell/Run.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public func run(_ command: String, with arguments: [String], input: String? = ni
1717
}
1818

1919
func run(at path: String, with arguments: [String], input: String? = nil) -> String? {
20-
return Task.run(path, arguments: arguments, input: Pipe(inputString: input)).outputString
20+
return Task.run(path: path, arguments: arguments, input: Pipe(inputString: input)).outputString
2121
}
2222

2323
func path(of command: String) -> String? {

SwiftShell/String.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
extension String {
1212

1313
func trimmedLastEndOfLine() -> String {
14-
guard let lastCharacter = self.characters.last, lastCharacter == "\n" else { return self }
14+
guard let lastCharacter = self.characters.last where lastCharacter == "\n" else { return self }
1515
return String(characters.dropLast())
1616
}
1717

SwiftShell/Task.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
extension Task {
1212

13-
static func run(_ path: String, arguments: [String] = [], output: Pipe? = nil, input: Pipe? = nil) -> Pipe {
13+
static func run(path: String, arguments: [String] = [], output: Pipe? = nil, input: Pipe? = nil) -> Pipe {
1414
let output = output ?? Pipe()
1515

1616
let task = Task()

0 commit comments

Comments
 (0)