# A nicer-looking ri

**URL:** <https://www.ruby-forum.com/t/a-nicer-looking-ri/70450>\
**Category:** Ruby\
**Created:** [September 29, 2006, 8:51am UTC](https://www.ruby-forum.com/t/a-nicer-looking-ri/70450 "2006-09-29T08:51:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnuvince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gnuvince](https://www.ruby-forum.com/u/gnuvince)\
**Post date:** [September 29, 2006, 8:51am UTC](https://www.ruby-forum.com/t/a-nicer-looking-ri/70450/1 "2006-09-29T08:51:23Z")

</div>

Hello !

I’m recently in a shell scripting mood, and I came up with some small  
code that makes ri output look a fair deal nicer (at least on my box).  
If you put the following function definition in your shell’s init script  
(such as .bashrc or .zshrc) and use ril instead of ri, you’ll be pleased  
😉

ril () {  
ri -T -f ansi “$@” | less -r  
}

I wish a good day (or night) to all of you…

```
Vince
```

---

<div class="post-metadata">

**Author:** ![gnuvince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gnuvince](https://www.ruby-forum.com/u/gnuvince)\
**Post date:** [September 29, 2006, 10:11am UTC](https://www.ruby-forum.com/t/a-nicer-looking-ri/70450/2 "2006-09-29T10:11:28Z")

</div>

On Sep 28, 2006, at 11:49 PM, Vincent F. wrote:

> }
> 
> I wish a good day (or night) to all of you…

Why not just set the RI and PAGER environment variables?

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![gnuvince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gnuvince](https://www.ruby-forum.com/u/gnuvince)\
**Post date:** [September 29, 2006, 10:21am UTC](https://www.ruby-forum.com/t/a-nicer-looking-ri/70450/3 "2006-09-29T10:21:29Z")

</div>

Hello !

> > ril () {  
> > ri -T -f ansi “$@” | less -r  
> > }
> 
> Why not just set the RI and PAGER environment variables?

That’s a good point, but you don’t always want less to have the -r  
option, don’t you ?

```
Vince
```

---

<div class="post-metadata">

**Author:** ![gnuvince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gnuvince](https://www.ruby-forum.com/u/gnuvince)\
**Post date:** [September 30, 2006, 2:46am UTC](https://www.ruby-forum.com/t/a-nicer-looking-ri/70450/4 "2006-09-30T02:46:53Z")

</div>

On Sep 29, 2006, at 1:19 AM, Vincent F. wrote:

> > > ril () {  
> > > ri -T -f ansi “$@” | less -r  
> > > }
> > 
> > Why not just set the RI and PAGER environment variables?
> 
> That’s a good point, but you don’t always want less to have the -r  
> option, don’t you ?

To be honest, I never use the pager with ri.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![gnuvince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gnuvince](https://www.ruby-forum.com/u/gnuvince)\
**Post date:** [October 2, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/a-nicer-looking-ri/70450/5 "2006-10-02T19:47:41Z")

</div>

On Oct 1, 2006, at 1:02 AM, Nobuyoshi N. wrote:

> > option, don’t you ?
> 
> Why doesn’t ri have --pager option?
> 
> […]

Thank you.

I will commit this after returning from AJAXWorld.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![gnuvince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/82dd89/32.png) [@gnuvince](https://www.ruby-forum.com/u/gnuvince)\
**Post date:** [October 1, 2006, 10:02am UTC](https://www.ruby-forum.com/t/a-nicer-looking-ri/70450/6 "2006-10-01T10:02:28Z")

</div>

Hi,

At Fri, 29 Sep 2006 17:19:42 +0900,  
Vincent F. wrote in [ruby-talk:217143]:

> > > ril () {  
> > > ri -T -f ansi “$@” | less -r  
> > > }
> > 
> > Why not just set the RI and PAGER environment variables?
> 
> That’s a good point, but you don’t always want less to have the -r  
> option, don’t you ?

Why doesn’t ri have --pager option?

# Index: lib/rdoc/ri/ri\_display.rb

RCS file: /pub/cvs/ruby/lib/rdoc/ri/ri\_display.rb,v  
retrieving revision 1.6  
diff -U 2 -p -r1.6 ri\_display.rb  
— lib/rdoc/ri/ri\_display.rb 24 Mar 2004 19:17:13 -0000 1.6  
+++ lib/rdoc/ri/ri\_display.rb 29 Sep 2006 10:41:04 -0000  
@@ -210,9 +210,14 @@ class DefaultDisplay

def setup\_pager

- unless @options.use\_stdout
- 

```
 for pager in [ENV['PAGER'], "less", "more", 'pager' 

```

].compact.uniq

- if pager = @options.pager
- 

```
 pagers = []

```

- 

```
 pagers << pager unless pager == true

```

- 

```
 pagers << pager if pager = ENV['PAGER']

```

- 

```
 pagers.concat(%w"less more pager")

```

- 

```
 pagers.uniq!

```

- 

```
 pagers.each do |pager|
   return IO.popen(pager, "w") rescue nil
 end

```

- 

```
 @options.use_stdout = true

```

- 

```
 @options.pager = false
 nil

```

end  
Index: lib/rdoc/ri/ri\_options.rb  
===================================================================  
RCS file: /pub/cvs/ruby/lib/rdoc/ri/ri\_options.rb,v  
retrieving revision 1.17  
diff -U 2 -p -r1.17 ri\_options.rb  
— lib/rdoc/ri/ri\_options.rb 22 Sep 2006 23:39:10 -0000 1.17  
+++ lib/rdoc/ri/ri\_options.rb 29 Sep 2006 10:34:20 -0000  
@@ -6,4 +6,5 @@ module RI  
require ‘rdoc/ri/ri\_paths’  
require ‘rdoc/ri/ri\_display’

- require ‘rdoc/ri/ri\_paths’

- 
# No not use a pager. Writable, because ri sets it if it

- 
# Pager to use. Writable, because ri sets it if it

# can’t find a pager

- attr\_accessor :use\_stdout

- attr\_accessor :pager

@@ -64,5 +65,5 @@ module RI  
[ “–gems”, nil, nil,  
"Include documentation from Rubygems:\n " +

- 

```
     (RI::Paths::GEMDIRS ? "#{Gem.path}/doc/*/ri" :

```

- 

```
     (RI::Paths::GEMDIRS ? "#{::Gem.path}/doc/*/ri" :
                           "No Rubygems ri found.") ],

```

@@ -79,4 +80,8 @@ module RI  
],

- 

```
   [ "--pager", "-P", "pager",

```

- 

```
     "Send output to the command to pagenate"

```

- 

```
   ],

```

- 

```
   [ "--no-pager", "-T", nil,
     "Send output directly to stdout."

```

@@ -218,5 +223,5 @@ module RI

```
 def initialize

```

- 

```
 @use_stdout = !STDOUT.tty?

```

- 

```
 @pager = STDOUT.tty?
 @width = 72
 @formatter = RI::TextFormatter.for("plain")

```

@@ -251,5 +256,6 @@ module RI  
when “–version” then show\_version  
when “–list-names” then @list\_names = true

- 

```
     when "--no-pager" then @use_stdout = true

```

- 

```
     when "--pager" then @pager = arg

```

- 

```
     when "--no-pager" then @pager = false
     when "--classes" then @list_classes = true

```

# Index: lib/rdoc/ri/ri\_paths.rb

RCS file: /pub/cvs/ruby/lib/rdoc/ri/ri\_paths.rb,v  
retrieving revision 1.7  
diff -U 2 -p -r1.7 ri\_paths.rb  
— lib/rdoc/ri/ri\_paths.rb 26 Jun 2006 18:10:30 -0000 1.7  
+++ lib/rdoc/ri/ri\_paths.rb 19 Sep 2006 06:02:58 -0000  
@@ -45,6 +45,7 @@ module RI  
begin  
require ‘rubygems’

- 

```
 GEMDIRS = Dir["#{Gem.path}/doc/*/ri"]

```

- 

```
 GEMDIRS.each { |path| RI::Paths::PATH << path }

```

- 

```
 if GEMDIRS = (Dir["#{::Gem.path}/doc/*/ri"] if 

```

defined?(::Gem.path))

- 

```
   PATH.concat(GEMDIRS)

```

- 

```
 end

```

rescue LoadError  
GEMDIRS = nil
