Created
January 17, 2020 12:14
-
-
Save 1syo/9358c6d9199237d63bca8abff25f0d91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PathName = function(path) { | |
this.path = path; | |
this.elements = path.split('/'); | |
this.length = this.elements.length; | |
} | |
PathName.prototype.serviceName = function() { | |
var string = this.elements[4]; | |
switch (string) { | |
case 'mwed.gist.github.com': | |
case 'gist.github.com': | |
var name = "gist"; | |
break; | |
case 'mwed.github.com': | |
case 'www.github.com': | |
case 'github.com': | |
var name = "github"; | |
break; | |
case 'mwed.bitbucket.org': | |
case 'www.bitbucket.org': | |
case 'bitbucket.org': | |
var name = "bitbucket"; | |
break; | |
case 'gitlab.com': | |
var name = "gitlab"; | |
break; | |
default: | |
var name = "unknown"; | |
break; | |
} | |
return name; | |
} | |
PathName.prototype.isGist = function() { | |
if (this.serviceName() == "gist") { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
PathName.prototype.fullPath = function() { | |
return this.path; | |
} | |
PathName.prototype.repositoryName = function() { | |
var string = ''; | |
if (!this.isGist()) { | |
string = this.elements[this.length-2] + '/'; | |
} | |
return string + this.elements[this.length-1]; | |
} | |
function run() { | |
var query = "{query}"; | |
var app = Application.currentApplication(); | |
app.includeStandardAdditions = true; | |
var result = app.doShellScript("zsh --login -c 'ghq list -p | grep -i " + query + "'"); | |
var items = result.split('\r'); | |
if (items.count > 1) { | |
items.pop(); | |
} | |
var json = {items: []}; | |
for(var item of items) { | |
var path = new PathName(item); | |
json.items.push({ | |
type: "file", | |
title: path.repositoryName(), | |
subtitle: path.fullPath(), | |
arg: path.fullPath(), | |
autocomplete: path.repositoryName(), | |
valid: true | |
}) | |
} | |
return JSON.stringify(json) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment