Skip to content

Commit

Permalink
fix(Shell): Sometimes up-arrow wasn't showing history
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed May 24, 2024
1 parent 82bbdbb commit 390d187
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/adapters/Shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 390d187

Please sign in to comment.