This is a meta gem that installs useful irb gems and configures them for you. It has a modular structure and supports multiple library-loading mechanisms, e.g. via autoload or threads, allowing you to use only the gems you need.
gem install irbtools
On Linux, you need xclip or xsel to use the clipboard: sudo apt-get install xclip
On Windows, you need ansicon to enjoy all the colors
On MacOS, you will need growl, if you want to use the g gem.
Wrong display widths?
When using double-width unicode chars, you need to paste the following snippet to your .irbrc.
Irbtools.replace_library_callback :fancy_irb do FancyIrb.start :east_asian_width => true end
This setting is deactivated by default because of performance issues.
To use it, put the following in your ~/.irbrc file (this file is loaded every time you start irb):
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8 require 'irbtools'
If the file does not exist, just create a new one.
It's possible to modify, which libraries should be loaded:
# don't require 'irbtools', but: require 'irbtools/configure' # here you can modify the libraries using the methods below Irbtools.start
If you don't want to load the default set of irbtools gems, you will have to use require 'irbtools/minimal' instead of configure. You need to use the below methods for adding libraries in this case or Irbtools won't modify anything of your irb ;).
To use irbtools within the rails console, you will have to add irbtools to your Gemfile in this way: (or there will be some bundler double require issues..)
gem 'irbtools', :require => 'irbtools/configure'
You can put Rails specific configuration in a ~/.railsrc file that gets only loaded in Rails environments.
See this blog post for some Rails goodies. Please open an issue/say +1 in the comments there to get that stuff packaged into a gem.
Included gems and libraries
See rbjl.net/40-irbtools-release-the-power-of-irb or read the commented source files to get some examples of what you can do with irbtools.
colorize ruby objects
(active record) tables and custom views for specific objects
use hash rockets for output and more colorization
helper methods that might be useful in every-day irb usage, e.g.: ls, cat, rq, rrq, ld, session_history, reset!, clear, dbg
easy clipboard access (copy & paste)
lets you open vim, hack something, and it gets loaded into the current session, also possible: yaml object editing
another, more flexible “start editor and it gets loaded into your irb session” plugin
nice debug printing (q, o, c, .m, .d) + useful pseudo-constants (Info, OS, RubyVersion, RubyEngine)
nice debug printing (ap) [also see wp from wirb/wp]
some colorful code view helpers :)
commands framework (commands also work in the shell!)
interesting method finder (mf)
object-oriented .ri method
- fileutils (stdlib)
cd, pwd, ln_s, mv, rm, mkdir, touch … ;)
Not included anymore
automatically corrects typos (method_missing hook)
If you have RVM installed, you can switch your gemset or ruby with gemset and use (use gemsets and rubies to get a list). The gemset can be changed within the session, while changing ruby starts a new one. Please also note that you need to have installed irbtools for that ruby version. I recommend installing it in the global gemset.
How to load more or less libraries
You have the following methods:
Irbtools.add_library(lib, options_hash, &block)
The options_hash defines the way in which Irbtools loads the library. Following options are possible
- (no options)/:start
The library is required on startup before doing anything else (before displaying the prompt)
- :thread => identifier
After loading everything else, the library is required in a thread (while continuing loading). You can choose any identifier, but if you take the same one for multiple libraries, they will be loaded in the same thread (in the order that you define)
- :late => true
The library is required just before showing the prompt (note: loading threads might still be in process)
- :late_thread => identifier
Same as :thread, but after loading late libraries.
- :sub_session => true
The library is loaded every time a sub-session starts (using IRB.conf[:IRB_RC]). In ripl, ripl-after_rc is used.
- :autoload => :Constant
Use Ruby's autoload feature. It loads the library as soon as the constant is encountered.
You can also apply a block that gets executed after the library is loaded (except for autoload, the code will executed on startup in this case). You can also just add callback block by using the Irbtools.add_library_callback or the Irbtools.replace_library_callback method.
When adding a new library, you should firstly consider some way to load it via :autoload. If not possible, try loading via thread. If that is not possible either, fallback to the default loading.
Hint: Faster start-up
You can get an about a second faster start-up time by changing the loading methods for wirb and fancy_irb to :thread (drawback: the hash rocket will not be used for the first result):
require 'irbtools/configure' Irbtools.remove_library :paint Irbtools.remove_library :fancy_irb Irbtools.add_library :paint, :late => true do Wirb.load_schema :classic_paint if defined? Wirb end Irbtools.add_library :fancy_irb, :thread => -1 do FancyIrb.start end Irbtools.start
The welcome message can be customized with Irbtools.welcome_message=
There are irbtools extension packages, which can be modified via:
These packages add/modify the libraries to be loaded. For an example, see irbtools-more.
TODO irbtools 1.1.0
Fix/Improve RVM stuff
Way to use irbtools without
Better hirb interaction
Show some features in README
Copyright © 2010-2011 Jan Lelis, rbjl.net, released under the MIT license.