diff --git a/src/adapters/Shell.mjs b/src/adapters/Shell.mjs index 07fa1781e..a8ace1815 100644 --- a/src/adapters/Shell.mjs +++ b/src/adapters/Shell.mjs @@ -76,10 +76,8 @@ class Shell extends Adapter { break } if (input.length > 0) { - fs.appendFileSync(historyPath, `${input}\n`) + this.#rl.history.push(input) } - const history = fs.readFileSync(historyPath, 'utf-8').split('\n').reverse() - this.#rl.history = history let userId = process.env.HUBOT_SHELL_USER_ID || '1' if (userId.match(/A\d+z/)) { userId = parseInt(userId) @@ -89,6 +87,9 @@ class Shell extends Adapter { await this.receive(new TextMessage(user, input, 'messageId')) this.#rl.prompt() }) + this.#rl.on('history', async (history) => { + await fs.promises.writeFile(historyPath, history.reverse().join('\n')) + }) try { this.#rl.prompt() this.emit('connected', this)