如何在node.js shell中实现选项卡完成?

我在node.js中查找这个function,但是我没有find它。
我可以自己实施吗? 据我所知,node.js不会在启动时加载任何文件(就像Bash对.bashrc所做的那样),我也没有注意到任何方式来重写shell提示符。

有没有一种方法来实现它,而无需编写自定义shell?

你可以猴子补丁REPL:

 var repl = require('repl').start() var _complete = repl.complete repl.complete = function(line) { ... _complete.apply(this, arguments) } 

只是作为参考。

readline模块具有readline.createInterface(options)方法,该方法接受一个可选的completerfunction,使选项卡完成。

 function completer(line) { var completions = '.help .error .exit .quit .q'.split(' ') var hits = completions.filter(function(c) { return c.indexOf(line) == 0 }) // show all completions if none found return [hits.length ? hits : completions, line] } 

 function completer(linePartial, callback) { callback(null, [['123'], linePartial]); } 

链接到api文档: http : //nodejs.org/api/readline.html#readline_readline_createinterface_options