rbenv irb history is not saving - ruby

I install ruby via rbenv-installer.
When I use irb console, I can use history by pressing up and down on keyboard. And when I exited from console and start it again, I can't use prewious history. When I press up-arrow-button, nothing was happened.
When I used rvm this option was working. How can I switch on it in rbenv?

I found this way for solving my problem. In file ~/.irbrc write:
require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
Found in this question: irb history not working

Create ~/.irbrc if it does not exist, and add the following line to it:
IRB.conf[:SAVE_HISTORY] = 1000

Related

Disable irb autocomplete

The latest version of irb introduced an autocomplete that is quite buggy and I don't generally like to be distracted by an autocomplete, any idea how I can disable it?
Related question: How to disable Pry autocomplete?
Try putting this in your ~/.irbrc
IRB.conf[:USE_AUTOCOMPLETE] = false
We can pass the --noautocomplete command line option when invoking IRB.
irb --noautocomplete
Alternatively we can set a configuration option in ~/.irbrc or one of the other locations specified in the documentation
IRB.conf[:USE_AUTOCOMPLETE] = false
Starting a Rails console will respect this configuration but for a one-off we can provide the command line option.
Be sure to pass any Rails options before the --
rails console --sandbox -- --noautocomplete
Linux: locate .irbrc file. If there is no .irbrc file - create one in your home folder - type the following command into terminal:
echo "IRB.conf[:CONTEXT_MODE] = 0" >> ~/.irbrc
Windows: locate .irbrc folder
C:\Users\Ben\ .irbrc
Then to disable autocomplete add this line to .irbrc file:
IRB.conf[:USE_AUTOCOMPLETE] = false

don't load readline module in irb

The readline extension on my OSX seems buggy.
$irb -f --noreadline
irb(main):001:0> "中文"
=> "中文"
$irb -f --readline
irb(main):001:0> \U+FFE4\U+FFB8\U+FFAD\U+FFE6
So I want to set --noreadline as default option for irb. how to do it?
p.s. I'm using RVM and Ruby 1.9.3p194.
Add the following to your ~/.irbrc file (create it if it doesn't exist):
IRB.conf[:USE_READLINE] = false
Alternatively, you can add this to /etc/irbrc if you want it to apply across user accounts, or foo/.irbrc if you want it to apply on a directory/project basis.
Here's a list of other useful config options.

Why won't macvim always use ruby 1.9.3?

I have installed yadr dotfiles, a set of vim, ruby, etc plugins.
I have the following line of Ruby code in a file foo.rb:
foo: bar
Note I used the ruby 1.9.3 syntax for symbol assignment/definition.
When I start macvim from command line using mvim foo.rb and save that file, everything works fine.
However, when I open macvim using open -a macvim and navigate to and open foo.rb, when I try to save the file I get a ruby-vim syntax error on foo: bar. When I change it to :foo => bar I don't get syntax errors.
Using open -a macvim to open macvim, and then entering :!ruby -v prints ruby 1.8.7
Using mvim . to open macvim, and then entering :!ruby -v prints ruby 1.9.3
Depending on how I open macvim, I get a different version of Ruby. How do I ensure that macvim always uses ruby 1.9.3 to evaluate my ruby code?
Thanks
It took me awhile to find a fix, but the issue is caused by MacVim not loading zsh the same way Terminal loads zsh.
The fix is easy enough and can be placed into your zshrc. See a commit from my dotfiles:
https://github.com/simeonwillbanks/dotfiles/commit/e0e19cfeff13f8bc99d8164217ddd84c6d7f9529
The commit references a full explanation which can be found here:
http://vim.1045645.n5.nabble.com/MacVim-and-PATH-tt3388705.html#a3392363
Hope this helps!

Ruby version 1.9.3 becomes 'un boot strapped'

It has been working fine, and then suddenly it thinks it is version 1.8.7 (the ruby that came with snow leopard), not 1.9.3 (the one running on rvm, and the one called in the shebang line.
It happened last night, the problem went away, and now it's back again. I have removed the stap line from my bash profile, quit terminal, put it back, quit terminal, restarted my machine. I am vexed I must admit.
Script:
#!/Users/ben/.rvm/bin/ruby-1.9.3-p0
puts RUBY_VERSION
Return: 1.8.7
Irb using rvm:
Using /Users/ben/.rvm/gems/ruby-1.9.3-p0
1.9.3p0 :001 > RUBY_VERSION
=> "1.9.3"
1.9.3p0 :002 >
It has been working fine, and then suddenly stopped, my .bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
I would update your scripts to use
#!/usr/bin/env ruby
As the "shebang" so it simply grabs the current ruby command. This will enable you to rvm use ... whatever you like and the scripts don't need to be changed.
Chances are you have a .rvmrc file lying around somewhere that's switching you back to your system ruby. Take a look through the directories you are navigating through and see if you can find one.

How do you save IRB inputs to a .rb file?

Might sound like a newbie question (and it is since I am new to Ruby and IRB) but is there a way to save the commands you did in IRB to file? I am playing with WATIR and would love to save all my inputs to file instead of copying and pasting each.
Thanks for the help!
On my machine I can put this in my .irbrc file (located in your home directory):
Kernel.at_exit {
File.open("irb.log", "w") do |f|
f << Readline::HISTORY.to_a.join("\n")
end
}
It creates a file irb.log that contains your readline history. Irb uses readline for command input. It might be configured not to use readline for some people, I don't know. And maybe the history will be truncated at some point, or maybe it'll be modified by certain commands you do in your irb session... but try it out and see if it works.
If you want the irb prompt and the result of each command to be included in the log, then just use tee to record the output of irb:
$ irb | tee irb.log
You can run vim in irb:
http://vimcasts.org/episodes/running-vim-within-irb/
Take a look at watir-console.
I found this question when looking to do the same thing. I ended up switching from IRB to Pry; it is a separate REPL project for Ruby that has a whole host of advanced features not supported in IRB.
Well worth a look.
Pry

Resources