diff --git a/lib/repl.js b/lib/repl.js index 01a595984d6cfe..18c81c438dee91 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -721,11 +721,11 @@ REPLServer.prototype.complete = function(line, callback) { // REPL commands (e.g. ".break"). var match = null; - match = line.match(/^\s*(\.\w*)$/); + match = line.match(/^\s*\.(\w*)$/); if (match) { completionGroups.push(Object.keys(this.commands)); completeOn = match[1]; - if (match[1].length > 1) { + if (match[1].length) { filter = match[1]; } diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index eb4e68ad18d772..d92377efebf791 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -260,3 +260,10 @@ putIn.run(['.clear']); testMe.complete('var log = console.lo', common.mustCall((error, data) => { assert.deepStrictEqual(data, [['console.log'], 'console.lo']); })); + +// tab completion for defined commands +putIn.run(['.clear']); + +testMe.complete('.b', common.mustCall((error, data) => { + assert.deepStrictEqual(data, [['break'], 'b']); +}));