A nicer-looking ri

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
:wink:

ril () {
ri -T -f ansi “[email protected]” | less -r
}

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

Vince

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. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

Hello !

ril () {
ri -T -f ansi “[email protected]” | 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

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

ril () {
ri -T -f ansi “[email protected]” | 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. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

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. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

Hi,

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

ril () {
ri -T -f ansi “[email protected]” | 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’

    VERSION_STRING = “ri v1.0.1 - 20041108”
    @@ -16,7 +17,7 @@ module RI
    include Singleton

  • 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

    should we just display a class list and exit

@@ -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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs