-
-
Notifications
You must be signed in to change notification settings - Fork 543
feat: command history #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { join } from 'path' | ||
| import * as os from 'os' | ||
| import * as fs from 'fs' | ||
|
|
||
| // TODO: Use `repl: REPLServer` when history-related properties are added to @types/node | ||
| export function useHistory (repl: any) { | ||
| repl.historySize = process.env.TS_NODE_HISTORY !== '' | ||
| ? Number(process.env.TS_NODE_HISTORY_SIZE || 1000) | ||
| : 0 | ||
|
|
||
| if (repl.historySize > 0) { | ||
| const file = process.env.TS_NODE_HISTORY || join(os.homedir(), '.ts_node_history') | ||
| if (fs.existsSync(file)) { | ||
| repl.history = fs.readFileSync(file, 'utf8').split(os.EOL) | ||
| } | ||
| repl.on('exit', () => { | ||
| fs.writeFileSync(file, repl.history.join(os.EOL)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this work with two processes running? It seems like one would just overwrite the other's history?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's how the |
||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a place for configuration loaded from environment variables, we should re-use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maintainer edits are enabled, if you want to help out.