Skip to content

Instantly share code, notes, and snippets.

@1syo
Created January 17, 2020 12:15
Show Gist options
  • Save 1syo/7752b9d18dbe43a2b6a06d40e0163ce0 to your computer and use it in GitHub Desktop.
Save 1syo/7752b9d18dbe43a2b6a06d40e0163ce0 to your computer and use it in GitHub Desktop.
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