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.
当我运行rails c并在irb启动时按下向上键,我可以看到我在遇到ruby-debug gem的调试器命令后我的应用程序掉到irb时输入的最后一个命令。我不仅希望清除这些命令,而且如果rails c将拉出我在上一次rails控制台会话期间发出的最后一个命令,我希望如此。我认为它曾经这样做,但我不确定发生了什么变化。如果有帮助的话,我在Mac OS 10.6.5上使用ruby 1.8.7和rails 3.0.3。
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.
Ray的回答在过渡时期帮助了我。最近我做了一些挖掘,以了解更多,并意识到存在许多相互矛盾的问题。
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
).
IRB检查你是否有〜/ .irbrc,如果没有,就像雷提到的那样回到/ etc / irbrc。但是,如果你正在使用rvm,还有另一个要考虑的文件〜/ .rvm / scripts / irbrc,如果在你的ENV中设置了rvm_path,它只会加载〜/ .rvm / scripts / irbrc.rb(注意.rb)(你应该使用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 -
).
有趣的是,虽然〜/ .rvm / scripts / irbrc.rb基于/ etc / irbrc,但它们并不相同,并且在某些方面有所不同。检测系统中使用哪一个的最明显的方法和最简单的方法是它们的历史文件名。如果正在使用/ etc / irbrc,你的历史文件将是〜/ .irb_history,其中rvm是〜/ .irb-history(注意:_ 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.
我已经停止使用调试器并转移到包含pry gem的pry-byebug。 Pry是IRB的替代品,但也可以在其旁边和内部使用。我能够提供上述更新的原因是因为我试图弄清楚如何将各自的历史分开。欲了解更多信息,请参阅我对SO问题的回答:“为什么撬历史会阻止历史?”。我已经为Pry包含了已知Github问题的链接以及我尝试修复它。
3 个解决方案
#1
9
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.
我将您的问题解释为询问如何在Rails控制台中打开历史记录并在Ruby调试器中关闭。如果不是这样,请澄清。
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.
IRB,以及Rails控制台,从〜/ .irbrc读取,或者如果不存在,则读取/ etc / irbrc,以启动和配置irb。您的历史记录通常写入〜/ .irb_history,但这取决于您的irbrc文件的内容。我的Mac OS X上的/ etc / irbrc设置为从irb写入历史记录,因此您可能创建了一个没有历史记录的本地.irbrc,或者您可能在该文件中有语法错误。
The debugger reads a file called .rdebugrc
on startup. You can turn off history in debug by adding this line to ~/.rdebugrc
:
调试器在启动时读取名为.rdebugrc的文件。您可以通过将此行添加到〜/ .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:
您还可以将调试输出设置为使用以下命令转到与irb读取不同的文件:
set history filename
These also work from the debug prompt, but aren't persistent.
这些也可以在调试提示符下工作,但不是持久的。
#2
5
There are a number of tools to help improve the irb experience. Bond and hirb are promising.
有许多工具可以帮助改善irb体验。邦德和希尔布很有希望。
Here is Comprehensive list of Irb Tools and some tips on directly editing the .irbrc file.
以下是Irb Tools的综合列表以及有关直接编辑.irbrc文件的一些提示。
Hope this help!
希望这有帮助!
#3
0
Although a very old question I got here by google. Turns out RVM slightly changed over time. Currently my IRB history (using rvm) is stored here:
虽然谷歌在这里提到了一个非常古老的问题。结果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
#1
9
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.
我将您的问题解释为询问如何在Rails控制台中打开历史记录并在Ruby调试器中关闭。如果不是这样,请澄清。
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.
IRB,以及Rails控制台,从〜/ .irbrc读取,或者如果不存在,则读取/ etc / irbrc,以启动和配置irb。您的历史记录通常写入〜/ .irb_history,但这取决于您的irbrc文件的内容。我的Mac OS X上的/ etc / irbrc设置为从irb写入历史记录,因此您可能创建了一个没有历史记录的本地.irbrc,或者您可能在该文件中有语法错误。
The debugger reads a file called .rdebugrc
on startup. You can turn off history in debug by adding this line to ~/.rdebugrc
:
调试器在启动时读取名为.rdebugrc的文件。您可以通过将此行添加到〜/ .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:
您还可以将调试输出设置为使用以下命令转到与irb读取不同的文件:
set history filename
These also work from the debug prompt, but aren't persistent.
这些也可以在调试提示符下工作,但不是持久的。
#2
5
There are a number of tools to help improve the irb experience. Bond and hirb are promising.
有许多工具可以帮助改善irb体验。邦德和希尔布很有希望。
Here is Comprehensive list of Irb Tools and some tips on directly editing the .irbrc file.
以下是Irb Tools的综合列表以及有关直接编辑.irbrc文件的一些提示。
Hope this help!
希望这有帮助!
#3
0
Although a very old question I got here by google. Turns out RVM slightly changed over time. Currently my IRB history (using rvm) is stored here:
虽然谷歌在这里提到了一个非常古老的问题。结果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