This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alfred.js
82 lines (70 loc) · 1.98 KB
/
alfred.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const alfy = require('alfy');
const luminate = require("./luminate");
const logger = require("./logger");
const maxResults = 10;
function getSshAccount(app) {
if (!app || !app.effectiveSecurityRole || !app.effectiveSecurityRole.customSshUserAccounts || !app.effectiveSecurityRole.customSshUserAccounts[0]) {
return "";
}
return app.effectiveSecurityRole.customSshUserAccounts[0].name;
}
function formatApplicationForAlfred(app) {
let arg = "";
let text = app.url;
let valid = false;
switch (app.type) {
case "HTTP": {
arg = app.url;
text = app.url;
valid = true;
break;
}
case "SSH": {
arg = `ssh://${getSshAccount(app)}@${app.name}@${app.url}`;
text = `ssh ${arg}`;
valid = true;
break;
}
}
return {
"uid": app.id,
"type": "file",
"title": app.name,
"valid": valid,
"subtitle": `[${app.type}] ${app.url}`,
"arg": arg,
"match": app.name,
"autocomplete": app.name,
"text": {
"copy": text,
},
"icon": {
//"type": "fileicon",
"path": app.icon,
}
}
}
function formatAppsForAlfred(apps) {
return apps.map((app) => formatApplicationForAlfred(app));
}
const filter = process.argv[2];
//alfy.log("Filter: " + filter)
(async () => {
try {
await luminate.authenticateToLuminate();
}
catch(e) {
alfy.error("Failed authenticating to luminate: " + JSON.stringify(e));
process.exit(1);
}
try {
let apps = await luminate.getApplications();
if (filter && apps) {
apps = apps.filter((a) => a.type.toLowerCase() === filter);
}
let formattedApps = formatAppsForAlfred(apps);
alfy.output(formattedApps);
} catch (e) {
alfy.error("Failed fetching applications. Error: " + JSON.stringify(e));
}
})();