diff --git a/tools/server/shell.js b/tools/server/shell.js index 4bf4b07a91..18ed0f7896 100644 --- a/tools/server/shell.js +++ b/tools/server/shell.js @@ -56,7 +56,7 @@ function onConnection(socket) { prompt: "> ", terminal: true, useColors: true, - useGlobal: false, + useGlobal: true, ignoreUndefined: true, }); @@ -77,6 +77,19 @@ function startREPL(options) { // History persists across shell sessions! initializeHistory(repl); + Object.defineProperty(repl.context, "_", { + // Force the global _ variable to remain bound to underscore. + get: function () { return _; }, + + // Expose the last REPL result as __ instead of _. + set: function(lastResult) { + repl.context.__ = lastResult; + }, + + enumerable: true, + configurable: false + }); + // Use the same `require` function and `module` object visible to the // shell.js module. repl.context.require = require;