Enable unicode support in IRB
Recently I tried to paste some unicode characters into my irb
session, but was greeted with the following:
irb(main):001:0> utf8_str = "r\U+FFC3\U+FFA9sum\U+FFC3\U+FFA9"
That's not what I expected! After some intrepid googling, this article by Henrik Nyh says the default OS X libedit
library that Ruby is compiled against doesn't have good unicode support.
I wanted to confirm that rbenv and ruby-build had linked to libedit
instead of a newer version of readline
.
$ cd ~/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/x86_64-darwin12.2.0
$ otool -L readline.bundle
readline.bundle:
/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
Let's fix that. Update homebrew and install the latest readline
lib:
$ brew update && brew install readline
Then, recompile ruby by manually setting the path to readline
using the CONFIGURE_OPTS
environment variable:
CONFIGURE_OPTS=--with-readline-dir=`brew --prefix readline` rbenv install 1.9.3-p374
We can confirm readline
was linked by running otool
again:
$ otool -L readline.bundle
readline.bundle:
/usr/local/opt/readline/lib/libreadline.6.2.dylib (compatibility version 6.0.0, current version 6.2.0)
Written by eddie cianci
Related protips
4 Responses
Or just start using Pry.
Thank you very much for this.
I had to do one other thing: make sure that the $LANG environment variable is set properly.
In my case (Mac OS X), this was blank, probably because of a Custom region setting in System Preferences.
Setting $LANG to something sensible (e.g., en_GB.UTF-8) fixed this longstanding problem on my machine.
For full details, see the unicodetitlecase wiki at https://github.com/cantab/unicodetitlecase/wiki/_pages
cantabip -
good to know, thanks for mentioning!
I also want to point out, Tim Pope has basically rolled up all the readline build integration into this rbenv plugin:
https://github.com/tpope/rbenv-readline
Thanks!