Created
January 17, 2020 12:15
-
-
Save 1syo/7752b9d18dbe43a2b6a06d40e0163ce0 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
function run() { | |
var query = "{query}"; | |
var app = Application.currentApplication(); | |
app.includeStandardAdditions = true; | |
var path = app.pathTo("home folder", {from:"user domain"}) + "/.ssh/config" | |
var fd = app.openForAccess(path, { writePermission: false }); | |
var text = app.read(fd, {as: "text"}); | |
app.closeAccess(fd); | |
var hosts = []; | |
for (var line of text.split("\n")) { | |
if (matched = line.match(/^Host\s([^*]+)/)) { | |
hosts.push(matched.pop()); | |
} | |
} | |
var json = {items: []} | |
var regExp = new RegExp(query); | |
for (var host of hosts.filter(host => regExp.test(host))) { | |
json.items.push({ | |
type: "default", | |
title: host, | |
arg: host, | |
valid: true | |
}) | |
} | |
return JSON.stringify(json); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment