Skip to content

Instantly share code, notes, and snippets.

@hron84
Created February 11, 2010 06:23
Show Gist options
  • Save hron84/301275 to your computer and use it in GitHub Desktop.
Save hron84/301275 to your computer and use it in GitHub Desktop.
IRB config
def view_hash(hash)
a = hash.is_a?(Hash) ? [hash] : hash
Hirb::Helpers::Table.render a, :vertical => true
end
if defined? IRB
require 'irb/completion'
require 'rubygems'
begin
require 'hirb'
Hirb::View.enable
rescue LoadError
# pass
end
histsupport = true
begin
require 'irb/ext/save-history'
rescue LoadError
histsupport = false
end
HISTFILE = "#{ENV['HOME']}/.irb.hist"
MAXHISTSIZE = 100
unless histsupport
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
puts "Custom history support enabled"
else
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = MAXHISTSIZE
IRB.conf[:HISTORY_FILE] = HISTFILE
end
module Kernel
def m(object=Object.new, pattern=nil)
if object.class.name == "DBus::ProxyObjectInterface"
methods = object.methods.keys.sort
else
methods = object.public_methods(false).sort
end
methods = methods.grep pattern unless pattern.nil?
#ObjectMethods.new(methods)
methods
end
end
if defined?(Hirb)
Hirb.add_view Hash, :method => :view_hash
end
end
if defined? RUBY_DESCRIPTION
puts RUBY_DESCRIPTION
else
if defined? JRUBY_VERSION
puts "ruby #{RUBY_VERSION} (jruby #{JRUBY_VERSION}) (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]"
else
puts "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]"
end
end
puts RUBY_COPYRIGHT.sub(/^[^-]+- /, "")
# vim: filetype=ruby ts=2 sw=2 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment