有没有办法让节点在会话之间保留命令行历史记录? [英] Is there a way to have node preserve command line history between sessions?
问题描述
当我从命令行不带参数运行 node
时,我进入了一个交互式 shell.如果我执行一些命令,退出节点并重新启动节点,向上箭头不会执行任何操作(我希望它滚动浏览我以前的命令).
When I run node
from the command line with no arguments, I enter an interactive shell. If I execute some commands, exit node, and restart node, the up arrow doesn't do anything (I'd like it scroll through my previous commands).
有没有一种方法可以交互调用节点,以便它记住我的旧命令?
Is there a way I can invoke node interactively such that it will remember my old commands?
推荐答案
你可以使用 rlwrap 将 node.js REPL 命令存储在历史文件中.
You could use rlwrap to store node.js REPL commands in a history file.
首先,安装 rlwrap(使用 apt-get 或 brew 等包管理器轻松完成).
First, install rlwrap (done easily with a package manager like apt-get or brew etc).
然后为节点添加别名:
alias node='env NODE_NO_READLINE=1 rlwrap node'
我在 OSX 上,所以我将该别名添加到我的 ~/.bash_profile
文件中,并通过 source ~/.bash_profile
重新加载我的 bash_profile 文件..和我可以走了!
I'm on OSX so I add that alias to my ~/.bash_profile
file, and would reload my bash_profile file via source ~/.bash_profile
.. and I'm good to go!
希望这会有所帮助!
这篇关于有没有办法让节点在会话之间保留命令行历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!