如何清除 Rails 控制台历史记录

发布于 2024-10-07 05:30:47 字数 1611 浏览 8 评论 0原文

当我运行 rails c 并在 irb 启动时按向上键时,我可以看到当我的应用程序在遇到 debugger 命令后下降到 irb 时输入的最后命令红宝石调试宝石。我不仅想清除这些命令,而且希望 rails c 能够提取我在上次 Rails 控制台会话期间发出的最后命令。我认为它曾经这样做过,但我不确定发生了什么变化。如果有帮助的话,我在Mac OS 10.6.5上使用ruby 1.8.7和rails 3.0.3。

更新

Ray答案 在此期间帮助了我。最近,我做了更多的挖掘以了解更多信息,并意识到存在许多相互冲突的问题。

IRB 检查您是否有 ~/.irbrc,如果没有,则返回到 /etc/irbrc,如 Ray 提到的。但是,如果您使用的是 rvm,则需要考虑另一个文件 ~/.rvm/scripts/irbrc,它只会加载 ~/.rvm/scripts/irbrc .rb(注意.rb)如果您在ENV中设置了rvm_path(如果使用rvm,则应该)。

有趣的是,虽然 ~/.rvm/scripts/irbrc.rb 是基于 /etc/irbrc 的,但它们并不相同,并且在一些方面有所不同。检测系统上正在使用哪个文件的最明显和最简单的方法是其历史文件的名称。如果使用/etc/irbrc,您的历史文件将是~/.irb_history,其中rvm的文件是~/。 irb-history注意_-)。

希望这些附加信息将帮助您确定根据需要设置系统所需的内容。

Pry 问题

我已经停止使用 debugger 并转而使用 pry-byebug,其中包含 pry gem。 Pry 是 IRB 的替代品,但也可以与 IRB 一起使用或在 IRB 内部使用。我之所以能够提供上述更新,是因为我试图弄清楚如何将它们各自的历史分开。有关更多信息,请参阅我的回答 SO问题“为什么撬历史会保留破坏irb历史? ”。我在那里提供了 Pry 的已知 Github 问题的链接以及我尝试修复该问题的链接。

When I run rails c and press the up key when irb starts up, I can see the last commands I entered when my app dropped to irb after encountering a debugger command for the ruby-debug gem. I would not only like to clear these commands out, but I would like it if rails c would pull the last commands I issued during my last rails console session. I think it used to do this but I'm not sure what has changed. I'm on ruby 1.8.7 and rails 3.0.3 on Mac OS 10.6.5 if that helps.

Update

Ray's answer helped me out in the interim. Recently I did a bit more digging to find out more and realized that there are a number of conflicting issues.

IRB checks if you have a ~/.irbrc and if not falls back to /etc/irbrc as Ray mentioned. However, if you are using rvm there is another file to consider ~/.rvm/scripts/irbrc which just loads up ~/.rvm/scripts/irbrc.rb (note the .rb) if you have rvm_path set in your ENV (you should if using rvm).

Interestingly while ~/.rvm/scripts/irbrc.rb was based off of /etc/irbrc they are not the same and differ in a few ways. The most obvious way and easiest way to detect which one is being used on your system is their history file's name. If /etc/irbrc is being used your history file will be ~/.irb_history where as rvm's is ~/.irb-history (Note: _ vs -).

Hopefully this additional information will help you determine what you need to setup your system as you would like.

Pry Concerns

I've since stopped using debugger and have moved to pry-byebug which includes the pry gem. Pry is an alternative to IRB but can also be used along side and within it. The reason I was able to provide the above update is because I was trying to figure out how to keep their respective histories separate. For more information please see my answer to the SO question on "why does pry history keep cloberring irb history?". I've included links there to the known Github issue for Pry as well as my attempt to fix it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他夏了夏天 2024-10-14 05:30:47

我将您的问题解释为询问如何在 Rails 控制台中打开历史记录并在 Ruby 调试器中关闭历史记录。如果这不是真的,请澄清。

IRB,以及扩展的 Rails 控制台,从 ~/.irbrc 读取,或者如果不存在,则从 /etc/irbrc 读取,以启动和配置 irb。您的历史记录通常写入 ~/.irb_history,但这由 irbrc 文件的内容决定。我的 Mac OS X 上的 /etc/irbrc 设置为从 irb 写入历史记录,因此您可能创建了一个没有历史记录的本地 .irbrc ,或者该文件中可能存在语法错误。

调试器在启动时读取名为 .rdebugrc 的文件。您可以通过将此行添加到 ~/.rdebugrc 来关闭调试中的历史记录:

set history save off

将其重新打开:

set history save on

您还可以将调试输出设置为转到与 irb 使用命令读取的文件不同的文件:

set history filename

这些也可以在调试提示符下工作,但不是持久的。

I interpret you question as asking how to turn history on in the Rails Console and off in the Ruby debugger. If this isn't true, please clarify.

IRB, and by extension, the Rails Console, read from ~/.irbrc, or if that doesn't exist, /etc/irbrc, to startup and configure irb. Your history is typically written to ~/.irb_history, but that is dictated by the contents of your irbrc file. The /etc/irbrc on my Mac OS X is set up to write the history from irb, so perhaps you've created a local .irbrc that doesn't have history, or perhaps you have a syntax error in that file.

The debugger reads a file called .rdebugrc on startup. You can turn off history in debug by adding this line to ~/.rdebugrc:

set history save off

Turn it back on with:

set history save on

You could also set your debug output to go to a different file than irb reads from with the command:

set history filename

These also work from the debug prompt, but aren't persistent.

纵山崖 2024-10-14 05:30:47

事实证明,RVM 随着时间的推移略有变化。
目前我的 IRB 历史记录(使用 rvm)存储在这里:

user@host:~$ ls ~/.rvm/rubies/ruby-2.4.2/.irbrc*
/home/user/.rvm/rubies/ruby-2.4.2/.irbrc
/home/user/.rvm/rubies/ruby-2.4.2/.irbrc_history

Turns out RVM slightly changed over time.
Currently my IRB history (using rvm) is stored here:

user@host:~$ ls ~/.rvm/rubies/ruby-2.4.2/.irbrc*
/home/user/.rvm/rubies/ruby-2.4.2/.irbrc
/home/user/.rvm/rubies/ruby-2.4.2/.irbrc_history
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文