|
|
@ -111,22 +111,34 @@ const doCommand = (line, settings) => { |
|
|
|
throw new Error(name + ' command is not defined'); |
|
|
|
throw new Error(name + ' command is not defined'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const getCompletions = (command, keywords, settings) => { |
|
|
|
const getCompletions = (line, settings) => { |
|
|
|
switch (command) { |
|
|
|
let typedWords = line.trim().split(/ +/); |
|
|
|
|
|
|
|
let typing = ''; |
|
|
|
|
|
|
|
if (!line.endsWith(' ')) { |
|
|
|
|
|
|
|
typing = typedWords.pop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typedWords.length === 0) { |
|
|
|
|
|
|
|
return Promise.resolve([]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let name = typedWords.shift(); |
|
|
|
|
|
|
|
let keywords = typedWords.concat(typing).join(' '); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (name) { |
|
|
|
case 'o': |
|
|
|
case 'o': |
|
|
|
case 'open': |
|
|
|
case 'open': |
|
|
|
case 't': |
|
|
|
case 't': |
|
|
|
case 'tabopen': |
|
|
|
case 'tabopen': |
|
|
|
case 'w': |
|
|
|
case 'w': |
|
|
|
case 'winopen': |
|
|
|
case 'winopen': |
|
|
|
return getOpenCompletions(command, keywords, settings.search); |
|
|
|
return getOpenCompletions(name, keywords, settings.search); |
|
|
|
case 'b': |
|
|
|
case 'b': |
|
|
|
case 'buffer': |
|
|
|
case 'buffer': |
|
|
|
return tabs.getCompletions(keywords).then((gotTabs) => { |
|
|
|
return tabs.getCompletions(keywords).then((gotTabs) => { |
|
|
|
let items = gotTabs.map((tab) => { |
|
|
|
let items = gotTabs.map((tab) => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
caption: tab.title, |
|
|
|
caption: tab.title, |
|
|
|
content: command + ' ' + tab.title, |
|
|
|
content: name + ' ' + tab.title, |
|
|
|
url: tab.url, |
|
|
|
url: tab.url, |
|
|
|
icon: tab.favIconUrl |
|
|
|
icon: tab.favIconUrl |
|
|
|
}; |
|
|
|
}; |
|
|
@ -147,9 +159,7 @@ const exec = (line, settings) => { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const complete = (line, settings) => { |
|
|
|
const complete = (line, settings) => { |
|
|
|
let command = line.split(' ', 1)[0]; |
|
|
|
return getCompletions(line, settings); |
|
|
|
let keywords = line.replace(command + ' ', ''); |
|
|
|
|
|
|
|
return getCompletions(command, keywords, settings); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export { exec, complete }; |
|
|
|
export { exec, complete }; |
|
|
|