Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement tab completion in node.js shell?

I was looking for this feature in node.js and I haven't found it.
Can I implement it myself? As far as I know, node.js doesn't load any file at it's startup (like Bash does with .bashrc) and I haven't noticed any way to somehow override shell prompt.

Is there a way to implement it without writing custom shell?

like image 727
Dr McKay Avatar asked Aug 17 '11 17:08

Dr McKay


1 Answers

You could monkey-patch the REPL. Note that you must use the callback version of the completer, otherwise it won't work correctly:

var repl = require('repl').start()
var _completer = repl.completer.bind(repl)
repl.completer = function(line, cb) {
  // ...
  _completer(line, cb)
}
like image 187
thejh Avatar answered Sep 28 '22 13:09

thejh