-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathfzf-node-completion.js
executable file
·34 lines (31 loc) · 1.35 KB
/
fzf-node-completion.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
// vi: ft=javascript
const child_process = require('node:child_process');
const repl = require('node:repl');
const start = repl.start;
repl.start = function(...args) {
const replServer = start(...args);
replServer.input.on('keypress', function(str, key) {
if (key.sequence == '\t') {
// sabotage the key so the repl doesn't get it
key.name = '';
key.ctrl = 1;
key.sequence = '';
replServer.completer(replServer.line.slice(0, replServer.cursor), function(error, [completions, prefix]) {
if (completions.length == 0) {
return;
}
let stdout = prefix;
const input = completions.filter(x => x !== '').join('\n');
try {
stdout = child_process.execFileSync('rl_custom_complete', [prefix], {input, stdio: ['pipe', 'pipe', 'inherit']}).toString().trim('\n');
} catch(e) {
}
replServer.line = replServer.line.slice(0, replServer.cursor - prefix.length) + stdout + replServer.line.slice(replServer.cursor);
replServer.cursor += stdout.length - prefix.length;
// fzf will have destroyed the prompt, so fix it
replServer._refreshLine();
});
}
});
return replServer;
};