File: irbrc

package info (click to toggle)
libtioga-ruby 1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,956 kB
  • ctags: 3,257
  • sloc: ansic: 31,801; ruby: 16,346; sh: 172; makefile: 114
file content (42 lines) | stat: -rw-r--r-- 1,328 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# sample for ~/.irbrc
# enables Tab completion
# uses simple prompt
# enables readline
# sets up history across sessions of irb
# sets up IRB_Tioga

require 'irb/completion'

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

HISTFILE = "~/.irb.hist"
MAXHISTSIZE = 100

begin
    if defined? Readline::HISTORY
        histfile = File::expand_path( HISTFILE )
        if File::exists?( histfile )
            lines = IO::readlines( histfile ).collect {|line| line.chomp}
            puts "Read %d saved history commands from %s." %
                [ lines.nitems, histfile ] if $DEBUG || $VERBOSE
            Readline::HISTORY.push( *lines )
        else
            puts "History file '%s' was empty or non-existant." %
                histfile if $DEBUG || $VERBOSE
        end
        
        Kernel::at_exit {
            lines = Readline::HISTORY.to_a.reverse.uniq.reverse
            lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE
            $stderr.puts "Saving %d history lines to %s." %
                [ lines.length, histfile ] if $VERBOSE || $DEBUG
            File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
                lines.each {|line| ofh.puts line }
                }
        }
    end
end

require 'Tioga/irb_tioga.rb'
include Tioga::IRB_Tioga