Jul 25, 2010

Making re.pl usable

For starters I'm not a super fan of interactive shell's for non-system shells. I don't see the point as much. When I first tried Devel::REPL I didn't like it at all, compared to every other interactive shell I've used (with the notable exception of Oracle's SQLPLUS, which is the worst shell ever) it was an unfriendly toy not worthy of mention. I couldn't go up in history, there was no tab completion, and all in all the default output was ugly no colors or formatting. I noticed in the docs
By default the re.pl program looks for (all of the following code goes in this file)$HOME/.re.pl/repl.rc, and runs whatever code is in there as if you had entered it at the REPL shell yourself.
and that re.pl has plugins, I also noticed some strange syntax and what seemed to be overly complicated code for just getting a few things working. Sure the file supports perl, but do I really want to write full perl programs in an RC file just to use plugins?

Well fortunately it's not as complex as all that. First thing you want to do is set some good perl defaults. Since this is our private shell might as well get all the current features of perl. Of course if you want to have other modules always accessible load them here to.

Now lets get some sanity into the shell by using plugins for REPL. It's really much simpler than the docs say. Wow that's way easier than what any of the documentation describes.

Ok let's look at some plugins. First if your typing isn't perfect you've probably noticed that you can't use your up arrow to go back in history, to fix this you can enable Readline support by loading Devel::REPL::Plugin::ReadlineHistory like so, This will allow you to up arrow to go back through lines you've previously typed, which you can then edit just like your normal *nix shell prompt. This one thing makes re.pl about 100x less annoying.

But I wish I had some kind of tab completion so I didn't have to type so much. Hey there's a whole set of completion plugins, lets enable those too.

So the Keywords Driver allows you to type pri< tab > and it'll complete print plus showing you printf just like your *nix shell. LexEnv will allow you to auto-complete your variable names and so on. There are a few more besides what I mentioned here.

Next I'll mention the Colors plugin. You may have noticed when you enter code such as my $var = 'blah'; say $var; you get the output
or the output text and return code. well if you enable colors the return code is now in green making it easy to distinguish between output and extra info.

Last but not least I'll mention DumpHistory, enabling DumpHistory allows you to Dump your input history to the screen or to a file.

Now we have a fully functioning, 'user' friendly, perl shell.

For your convenience here's my current file


  1. Thanks for the great tips, Khalib!

  2. Thanks for this, it was really helpful. I found that I also needed to install

    - File::Next
    - B::Keywords
    - Term::ReadLine::Gnu

    before the plugins worked.


No trolling, profanity, or flame wars :: My Blog, my rules! No crying or arguing about them.