irbtools / Release the power of irb!
Equipped with some tools discussed at the germany.rb 2010 user group meetup, I’ve played around with my ~/.irbrc
and put together a little meta gem for some useful irb tools (github)
Features
- Colorized and output as comment by wirb and fancy_irb
- Nice IRB prompt and IRB’s auto indention
- Includes stdlib’s FileUtils:
ls
,cd
,pwd
,ln_s
,rm
,mkdir
,touch
,cat
- Many debugging helpers:
ap
,q
,o
,c
,y
,Object#m
,Object#d
ap
– awesome_printq
– likep
, but on one lineObject#m
– ordered method list (takes integer parameter: level of nesting)Objedt#d
– puts the object, returns self (usingtap
)
- “Magical” information constants:
Info
,OS
,RubyVersion
,RubyEngine
OS.windows?
RubyEngine.jruby?
RubyVersion.is.at_least? 1.9
- Clipboard features:
copy
andpaste
- also available:
copy_input
andcopy_output
for session history
- also available:
- Call
vim
(or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered by interactive_editor - Another way of live loading into irb: sketches
- Highlight a string with
colorize('string')
or a file withray('path')
, powered by coderay - Displays ActiveRecord database entries as tables with hirb
- Restart irb with
reset!
or change the Ruby version with theuse
method and rvm! - Includes the current directory in the load path (was removed in 1.9.2 for security reasons, but is pretty annoying in IRB)
- Shorter requiring like this:
rq:mathn
- And rerquiring with
rrq
- Try the included
Object#ri
helper, powered by ori! - Access to a lot of more commands with boson – call
commands
to get started
Screenshots
Setup
gem install irbtools
On Linux, you also need to sudo apt-get install xclip
On MacOS, you can install growl to use the g gem.
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 # only needed in 1.8
require 'irbtools'
If it does not exists, just create a new one.
It’s is possible to modify, which libraries get loaded:
# no require 'irbtools'
require 'irbtools/configure'
# edit libraries using Irbtools.add_library and Irbtools.remove_library
Irbtools.start
RVM hint
You can add irbtools to ~/.rvm/gemsets/global
and it will be installed automatically for new rubies.
By the way
Sometimes, you need a clean IRB without all the .irbrc
libraries. In such a case, just start irb
with the -f
option and it will suppress loading the .irbrc
.
Update
I’ve now released irbtools-more
, which installs even more useful gems, which may not build out-of-the-box.
- DrX object inspector:
Object#see
, requirestk
- Better auto completion, using Bond
rivsc | October 07, 2010
How to work with rails 3 ? I've added irbtools and irb_rocket in my Gemfile, but "rails c" crash :
no method in threshold: merge! for nil:NilClass
/usr/lib/ruby/gems/1.8/gems/guessmethod-0.2.1/lib/guessmethod.rb:10:in `unguessed_method_missing': undefined method `merge!' for nil:NilClass (NoMethodError)
J-_-L | October 07, 2010
Hi rivsc,
I will investigate this. As a workaround, you can do:
<code>require 'irbtools/configure'
Irbtools.libs -= %w[guessmethod]
Irbtools.init</code>
Lucas Efe | October 07, 2010
Hi, Rivse, the problem is not on guess method, but on irbtools.rb, where the IRB prompt is being set. I am having the same problem. I will investigate... :)
Lucas Efe | October 07, 2010
Sorry, rivse no, I meant janlelis.
J-_-L | October 07, 2010
Yep, sry, it's fixed with version 0.7.2
zigzo | October 07, 2010
Fantastic! This is my first shot at using a beautified IRB prompt and so far it's great! thank you!!
rivsc | October 08, 2010
Thanks ! It works with version 0.7.2, but hirb doesn't work ! (my hirb : the last version 0.3.4)
J-_-L | October 08, 2010
Hey rivsc, I am working on a fix. As a workaround, you can disable irb_rocket.
J-_-L | October 12, 2010
I've released 0.8.0. It fixes the hirb-irb_rocket problem, some guessmethod-rails bugs and more.
tianyicui | October 28, 2010
Just knew irbtools via thechangelog.com, it is fantastic! Thank you very much! But irb_rocket seems really buggy (at least in my 1.9.2 it hangs my irb A LOT) and I have to disable it. How about move it to `irbtools-more`?
J-_-L | October 31, 2010
I really like irb_rocket, but you are right, it can cause some headaches. I think, I'll just let it there and silence the warning if it is not installed. Thanks for the feedback :)