Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails console issues using JRuby: no prompt character, no tab completion, broken arrow keys, etc

Tags:

I'm having various issues with my Rails console under JRuby, including

  • No prompt character
  • Tab completion not working (literal tab gets inserted)
  • Up/down arrows not browsing history (^[[A or ^[[B gets inserted, respectively)
  • Left/right arrows not moving cursor (^[[D or ^[[C gets inserted, respectively)
  • Home/End keys not moving cursor to beginning/end of line (instead 1~ or 4~ inserted, respectively); Ctrl+a / Ctrl+e work though
  • Ctrl+c killing console instead of killing the line I'm entering
  • Ctrl+d not having any effect until I hit Enter (which then executes anything I entered between Ctrl+d and Enter in my Unix shell).

I installed my JRuby interpreter from rvm like so:

rvm install jruby-1.6.8 --1.9

My Rails project is managed using Bundler (not rvm gemsets), so I run my Rails console using bundle exec rails c. Interestingly, raw irb as well as bundle exec irb don't have most of the above issues, except the Home/End keys and Ctrl+c needs an Enter before I get a fresh prompt line.

I can replicate the issue with a barebones Rails Gemfile:

source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'sqlite3'

My shell is zsh, on Ubuntu 12.04 64-bit. $JAVA_HOME is /usr/lib/jvm/java-7-openjdk-amd64, but it might have still been java-6 when I installed this interpreter, if that matters.

Update: Some fixes

The missing prompt character is apparently caused by the IRB.conf[:PROMPT_MODE] getting set to :NULL by the Rails console. For regular irb, mine gets set to :RVM (apparently rvm does this in ~/.rvm/scripts/irb.rb; I ruled out rvm causing this issue by commenting out the script). Providing a :PROMPT_MODE value in ~/.irbrc fixes this. I thought maybe a similar issue was causing the Ctrl+c / Ctrl+d problems by changing :IGNORE_SIGINT and :IGNORE_EOF, but they are both set to their default values.

Tab completion and arrow keys get fixed by setting :USE_READLINE to true.

Here's my current ~/.irbrc that seems to fix said issues:

require 'irb/completion'

IRB.conf[:PROMPT_MODE]  = :SIMPLE
IRB.conf[:USE_READLINE] = true
IRB.conf[:AUTO_INDENT]  = true