-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 858 Bytes
/
index.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
const arvish = require('arvish');
const _ = require('lodash');
const shellHistory = require('shell-history');
const conf = require('./conf');
const getPluginItems = async ({ inputStr }) => {
if (inputStr && inputStr.startsWith(conf.prefix)) {
const command = inputStr.split(conf.prefix)[1].trim();
const historyItems = arvish.matches(command, shellHistory()).slice(0, conf.logCnt).map((commandLog) => {
return {
title: commandLog,
subtitle: `Execute '${commandLog}' on your terminal`,
arg: commandLog,
};
});
const items = _.uniqBy([
{
title: command,
subtitle: `Execute '${command}' on your terminal`,
arg: command,
},
...historyItems
], 'title');
return {
items
};
}
return {
items: [],
};
};
module.exports = getPluginItems;