Interactive/inline editor in irb

I saw the MountainWest Ruby conference video: code generation: safety scissors of metaprogramming. And the speaker (Giles Bowkett) used vi from inside irb. And I’ve never liked Vi, but using an editor from within irb is nice! Especially if you’re testing a big chunk of code.

So I began crawling the Internet for how he did this and I found the utility_belt gem. The utility belt contains the file I needed. So I installed the gem, edited my .irbrc and now I can use nano/gedit (or any other editor) from withing IRB!

These were the steps:

gem install utility_belt

My .irbrc:

require 'utility_belt/interactive_editor'
module InteractiveEditing
def nano
edit_interactively(:nano)
end
end

Now to use nano in irb, just type: nano

And the bonus: a nice screencast that shows this feature in action. I tried to edit it with pitivi. But that really sucked. After I finally found it out how I could cut pieces I tried to save it and the whole program crashed. “apt-get remove pitivi”!

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment