diff --git a/README.md b/README.md index 23f4b0f..ea9db67 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Search bookmarks in SourceTree and launch them in Alfred. ## Usage launch alfred then input `st` and `keyword` separated with a space to search bookmarks, press enter to launch the bookmark in SourceTree. +> press `cmd` + `enter` to reveal the repo in Finder ## Contributions and Support I'm new to swift, feel free to make a pull request if you are willing to improve the code quality or its functions. diff --git a/SourceTree.alfredworkflow b/SourceTree.alfredworkflow index 3c1ac34..34a786c 100644 Binary files a/SourceTree.alfredworkflow and b/SourceTree.alfredworkflow differ diff --git a/workflow.swift b/workflow.swift index 0c1a5d7..5ab7caa 100755 --- a/workflow.swift +++ b/workflow.swift @@ -4,9 +4,13 @@ import Foundation class SourceTree { init() { } - - func parsePlist () { + + func run () { guard let data = try? Data(contentsOf: plistPath) else { + let alfredResult = AlfredResult(items: [ + AlfredItem(title: "SourceTree not installed", subtitle: "Press enter to open SourceTree homepage and download it", arg: "open \"https://sourcetreeapp.com/\"") + ]) + prettyPrint(alfredResult) return } do { @@ -14,8 +18,32 @@ class SourceTree { let alfredResult = toAlfredResult(parsed.objects) prettyPrint(alfredResult) } catch { - print("failed to parse: ") - print(error) + let githubNewIssueUrl = "https://github.com/oe/sourcetree-alfred-workflow/issues/new" + var urlComponents = URLComponents(string: githubNewIssueUrl)! + let issueBody = """ + error message: + \(error.localizedDescription) + + environment info: + macOS version: [pleaase fill your version] + swift version: [run `swift --version` to get its version] + """ + let queryItems = [ + URLQueryItem(name: "title", value: "SourceTree plist parse error"), + URLQueryItem(name: "body", value: issueBody) + ] + if urlComponents.queryItems == nil { + urlComponents.queryItems = [] + } + urlComponents.queryItems!.append(contentsOf: queryItems) + let alfredResult = AlfredResult(items: [ + AlfredItem( + title: "Error occurred", + subtitle: "Press enter to open github and report an issue to me", + arg: "open \"\(urlComponents.url?.absoluteString ?? githubNewIssueUrl)\"" + ) + ]) + prettyPrint(alfredResult) } } @@ -40,9 +68,14 @@ class SourceTree { name = str } } + + var items: [AlfredItem] = namePathGroups.map { (name, path) in + let mod = AlfredItemModItem(valid: true, arg: "open \"\(path)\"", subtitle: "Reveal in Finder") + return AlfredItem(title: name, subtitle: path, match: spaceWords(name), arg: path, mods: AlfredItemMod(cmd: mod)) + } - let items = namePathGroups.map { (name, path) in - AlfredItem(title: name, subtitle: path, arg: path, match: spaceWords(name)) + if items.isEmpty { + items.append(AlfredItem(title: "Your SourceTree Bookmark Is Empty ", subtitle: "Please add repos to SourceTree first")) } return AlfredResult(items: items) @@ -70,8 +103,19 @@ class SourceTree { struct AlfredItem: Codable { var title: String var subtitle: String + var match: String? + var arg: String? + var mods: AlfredItemMod? + } + + struct AlfredItemMod: Codable { + var cmd: AlfredItemModItem + } + + struct AlfredItemModItem: Codable { + var valid: Bool var arg: String - var match: String + var subtitle: String } struct SourceTreePlist: Codable { @@ -114,4 +158,4 @@ extension UnkeyedDecodingContainer { } } -SourceTree().parsePlist() +SourceTree().run()