Posts Tagged ‘os x’

Running ‘ri’ with colors under Mac OS X

Tuesday, July 29th, 2008

Ruby has a command line utility called ri for looking up documentation, and ri has a nice feature of displaying its output with pretty colors. Unfortunately, when I tried to run it (ri -f ansi) what I got was:

After tinkering about a bit I gave up. But today I decided that I’ll have my damned pretty colors even if I have to spend a lifetime getting them! Thankfully it only took 10 minutes. ri uses less to display its output in a scrollable form, if you make it not use less you get what you want by giving it the -T option:

“But…but…but… I like scrollable output!”, says you, whimpering softly.

Well, stop your cryin’, so do I.

less itself takes an option to treat escape characters as escape characters (duh!) instead of just printing them. So you want to make it use it. Here’s what you want to add to your Bash profile file to make the magic happen:

# I likes pretty colors!!!1!!
export RI="-f ansi"
export LESS="-R"

And the result is: