IRB历史记录不适用于Ruby 2.3.0 [英] IRB history not working with Ruby 2.3.0

查看:101
本文介绍了IRB历史记录不适用于Ruby 2.3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OS X 10.11.4上通过rbenv安装了Ruby 2.3.0p0.在IRB会议中,历史记录很好.但是,我无法跨会话访问IRB历史记录.

I have Ruby 2.3.0p0 installed via rbenv, on OS X 10.11.4. Within an IRB session, history works fine. However, I cannot access IRB history across sessions.

我尝试了我的系统Ruby 2.0.0p648,并且跨IRB会话的历史记录运行良好.我尝试通过rbenv安装相同版本的Ruby,并且它也具有运行历史.

I tried my system Ruby, 2.0.0p648, and history across IRB sessions works fine. I tried installing that same version of Ruby via rbenv, and it also has working history.

我已经在工作会话和非工作会话之间比较了IRB.conf的值,并且看起来没有什么不妥(尽管,奇怪的是, irb/ext/save-history.rb 是空白的两种情况下都是文件).

I've compared the values of IRB.conf between a working and nonworking session, and nothing looks out of place (although, weirdly, irb/ext/save-history.rb is a blank file in both cases).

查看我的.irb_history文件,似乎该文件已被最新会话中的命令代替而不是附加.我可以加载2.0.0 IRB会话并在这些命令中滚动.

Looking at my .irb_history file, it appears that it is getting replaced, rather than appended, with the commands from the latest session. I can load up a 2.0.0 IRB session and scroll through those commands just fine.

我已经尝试了 rbenv irb历史记录未保存没有成功.

I've tried the answers listed in rbenv irb history is not saving without success.

我还尝试了 irb历史记录无效中的选定答案. 我不得不更改选择的答案以替换#nitems方法.这表明正在从历史记录文件中读取行,并将其推送到Readline::HISTORY.但是,检查Readline::HISTORY在那里什么都没有.

I also tried the selected answer in irb history not working. I had to alter the selected answer to replace the #nitems method. This showed that lines were being read out from the history file, and pushed on to Readline::HISTORY. However, examining Readline::HISTORY shows nothing there.

我可以通过Readline.readline将我的.irb_history的前几行添加到Readline历史记录中,并指定add_hist = true,从而对历史记录有所帮助.但是,绝对不是将以前的命令添加到Readline的正确方法.

I can sort of hack in history by adding previous lines from my .irb_history to the Readline history via Readline.readline, and specifying add_hist=true. However, it is definitely not the proper way to add the previous commands to Readline.

我知道我可以切换到撬"之类的东西,但是我想弄清楚这一点. 关于为何未将命令添加到Readline以及如何进行更改的任何建议?

I know I can switch over to something like pry, but I'd like to figure this out. Any suggestions on why the commands are not being added to Readline, and how to change that?

推荐答案

OS X的命令行编辑基于libedit库. OS X具有readline库的一个版本,该版本是libedit的包装,但是它的行为并不完全像GNU readline. irb历史记录可在使用OS X直至Ruby 2.1的包装器构建的Ruby中使用,但是Ruby 2.2及更高版本需要使用GNU readline构建,以使irb历史记录正常工作.

OS X's command-line editing is based on the libedit library. OS X has a version of the readline library which is a wrapper around libedit, but it does not behave completely like GNU readline. irb history works in Ruby built with OS X's wrapper up to Ruby 2.1, but Ruby 2.2 and later need to be built with GNU readline for irb history to work.

在下面,2.3.0可以是2.2.0以后的任何Ruby版本.我写了2.3.0,因为那是Evan使用的.

In the following, 2.3.0 can be any Ruby version from 2.2.0 on. I wrote 2.3.0 since that's what Evan used.

使用自制软件

如果您使用自制软件安装ruby,它将带来readline的有效版本.

If you install ruby using homebrew, it will bring with a working version of readline.

  • brew install ruby

然后按照说明将其添加到您的PATH中.然后执行 gem install irb(如果显示can't find gem irb.

Then follow the instructions to add it to your PATH. Then execute gem install irb if it says can't find gem irb.

使用MacPorts

rbenv不了解MacPorts,因此您需要明确告诉它使用MacPorts的阅读行.

rbenv doesn't know about MacPorts, so you need to explicitly tell it to use MacPorts' readline.

  • sudo port install readline(如果尚未安装).
  • rbenv uninstall 2.3.0
  • RUBY_CONFIGURE_OPTS=--with-readline-dir=/opt/local rbenv install 2.3.0
  • sudo port install readline if it isn't installed already.
  • rbenv uninstall 2.3.0
  • RUBY_CONFIGURE_OPTS=--with-readline-dir=/opt/local rbenv install 2.3.0

将Homebrew与rbenv一起使用

rbenv自动检测到自制程序并在其中查找读取行,因此,如果您使用的是Homebrew且irb历史记录不起作用,则说明您尚未安装readline,或者在安装readline之前先构建了Ruby.

rbenv automatically detects homebrew and looks in it for readline, so, if you're using Homebrew and irb history doesn't work, you either haven't installed readline or you built your Ruby before you installed readline.

  • brew install readline(如果尚未安装)
  • rbenv uninstall 2.3.0
  • rbenv install 2.3.0
  • brew install readline if it isn't installed already
  • rbenv uninstall 2.3.0
  • rbenv install 2.3.0

这篇关于IRB历史记录不适用于Ruby 2.3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆