Skip to content
irbtools is a meta gem that installs useful irb gems and configures your irb.
Ruby
Pull request Compare This branch is 3 commits ahead, 144 commits behind janlelis:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
screenshots
.gitignore
CHANGELOG
LICENSE
README.rdoc
Rakefile
VERSION
every_day_irb.gemspec
irbtools.gemspec

README.rdoc

irbtools

This is a meta gem that installs useful irb gems and configures your irb. It has a modular structure and supports multiple library-loading mechanisms, e.g. via autoload or threads.

Setup

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 should need to pass the :east_asian_width = true when starting FancyIrb. It is deactivated because of performance issues.

Usage

To use it, put the following in your ~/.irbrc file (this file is loaded every time you start an irb):

require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
require 'irbtools'

If it does not exist, just create a new one.

It's possible to modify, which libraries get loaded:

# don't require 'irbtools'
require 'irbtools/configure'
# here you can modify which libraries get loaded (see below)
Irbtools.start

You can also deactivate the loading of the complete default set of irbtools libraries by using require 'irbtools/minimal' instead of configure. You need to use the below methods for adding libraries in this case, or it won't modify anything of your irb ;).

Rails notes

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 which gets loaded only in Rails environments.

How to load more or less libraries

You have the following ways:

  • Irbtools.add_library(lib, options_hash, &block)

  • Irbtools.remove_library(lib)

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).

When adding a new library, you should consider adding it via autoload, try loading it via thread if autoload is not suitable and fallback to some other method, if not via thread is not possible.

See the Irbtools.libraries hash for the current Irbtools configuration that actually will be used when calling Irbtools.start.

Packages

There are irbtools extension packages, which can be modified via:

  • Irbtools.add_package(pkg)

  • Irbtools.remove_package(pkg)

These packages add/modify the libraries to be loaded. For an example, see irbtools-more.

Features

See rbjl.net/40-irbtools-release-the-power-of-irb or read the commented source files.

Included gems and libraries

  • wirb colorize output

  • hirb (active record) tables and custom views for specific objects

  • fancy_irb put result as comment and more colorization

  • every_day_irb helper methods that might be useful in every-day irb usage, e.g.: ls, cat, rq, rrq, ld, session_history, reset!, clear, dbg

  • clipboard easy clipboard access (copy & paste)

  • interactive_editor lets you open vim, hack something, and it gets loaded into the current session, also possible: yaml object editing

  • sketches another, more flexible “start editor and it gets loaded into your irb session” plugin

  • zucker nice debug printing (q, o, c, .m, .d) + useful pseudo-constants (Info, OS, RubyVersion, RubyEngine)

  • ap nice debug printing (ap) [also see wp from wirb/wp]

  • coderay some colorful code displaying ;)

  • boson commands repository (commands also work in the shell!)

  • methodfinder interesting method finder (mf)

  • ori object-oriented ri method

  • fileutils (stdlib) cd, pwd, ln_s, mv, rm, mkdir, touch … ;)

Not included anymore

  • guessmethod automatically corrects typos (method_missing hook)

RVM

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.

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 :wirb
Irbtools.remove_library :fancy_irb
Irbtools.add_library :wirb, :thread => -1 do Wirb.start end
Irbtools.add_library :fancy_irb, :thread => -1 do FancyIrb.start end
Irbtools.start

Welcome message

The welcome message can be customized with Irbtools.welcome_message=

Copyright

Copyright © 2010-2011 Jan Lelis, rbjl.net, released under the MIT license.

J-_-L

Something went wrong with that request. Please try again.