Skip to content

Commit

Permalink
fix(Shell): History wasn't working when hitting the up and down arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed May 21, 2024
1 parent 47d33ea commit b66760f
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/adapters/Shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,15 @@ class Shell extends Adapter {
this.#rl.prompt()
break
}
if (input.length > 0) {
fs.appendFileSync(historyPath, `${input}\n`)
}
const history = fs.readFileSync(historyPath, 'utf-8').split('\n').reverse()
this.#rl.history = history
this.#rl.on('line', line => {
const input = line.trim()
if (input.length === 0) return
fs.appendFile(historyPath, `${input}\n`, err => {
if (err) console.error(err)
})
})
let userId = process.env.HUBOT_SHELL_USER_ID || '1'
if (userId.match(/A\d+z/)) {
userId = parseInt(userId)
}

const userName = process.env.HUBOT_SHELL_USER_NAME || 'Shell'
const user = this.robot.brain.userForId(userId, { name: userName, room: 'Shell' })
await this.receive(new TextMessage(user, input, 'messageId'))
Expand Down

0 comments on commit b66760f

Please sign in to comment.