Nothing Special   »   [go: up one dir, main page]

Skip to content
/ ripl Public

ruby interactive print loop - A light, modular alternative to irb

License

Notifications You must be signed in to change notification settings

cldwalker/ripl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

ripl is a light shell that encourages common middleware for shells i.e. rack for ruby shells. It is also a modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports commands i.e. ripl-play. This customizability makes it easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the web). Works on ruby 1.8.7 and greater.

Install

If you have readline, install ripl with:

gem install ripl

If you don’t have readline, first install ripl with a pure ruby readline:

gem install ripl rb-readline -- --without-readline

Then, add the following to ~/.riplrc:

Ripl.config[:readline] = 'rb-readline'
Ripl.config[:completion] = {:readline => :ruby }

Setup

To make your first ripl experience smoother, install these plugins:

# Adds multi-line evaluation
gem install ripl-multi_line

# Ignore errors caused by irb-specific configuration in ~/.irbrc
gem install ripl-irb

# Add to ~/.riplrc
require 'ripl/multi_line'
require 'ripl/irb'

Usage

$ ripl
>> ...

Documentation

To view ripl’s man page:

# If installed with rubygems
$ gem install gem-man
$ gem man ripl

To view ripl’s documentation online, read [the source](github.com/cldwalker/ripl/blob/master/man/ripl.1.ronn) or [the html version](rawgit.com/cldwalker/ripl/master/man/ripl.1.html).

Coming from irb

When first trying ripl, you may experience errors in your ~/.irbrc due to an irb-specific configuration. In order to have ripl and irb coexist peacefully, you should silence these errors. To silence them without touching your ~/.irbrc, install the ripl-irb gem. This ripl plugin fakes irb’s existence and points to ripl equivalents for your irb configurations. Otherwise, if you don’t mind modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:

if defined? IRB
  IRB.conf[:BLAH] = 'blah'
  # ...
end

Comparison to Irb

  • Similar to irb

    • Reads ~/.irbrc on startup

    • Appends to ~/.irb_history on exit

    • Autocompletion (from bond)

    • _ for last result

    • Type exit, quit or press Ctrl-D to exit

    • 6 common commandline options: -f, -r, -I, -d, -h, -v

    • IRB.conf -> Ripl.config

    • Handles Ctrl-C quietly

  • Enhancements over irb

    • ~290 lines (doc included) vs irb’s 5000+ lines

    • Easily extendable with plugins

    • Tests and documentation!

    • Customizable completion and completion of method arguments (from bond)

    • Easy to create custom shells for gems and apps i.e. Ripl.start

    • Easy to create and invoke ripl commands

    • Create console commands in a simple, modular way

    • Custom commandline options can be added via a plugin

    • ~/.irbrc errors caught

    • Well-integrated internationalization (see ripl-i18n)

  • Different from irb

    • No multi-line evaluation by default (but there is a plugin, ripl-multi_line).

    • No irb subsessions or workspaces (though ripl has jumps via ripl-commands)

    • Some IRB.conf features aren’t supported yet (see ripl-irb for details)

Note: Irb features not in ripl can be implemented as plugins.

Plugins

A ripl plugin is a module that is included into Ripl::Shell or extended into Ripl::Runner. Being simply modules, they can be packaged as gems and reused across shells as needed. ripl highly encourages plugins by loading them as early as possible and allowing them to extend most of ripl’s functionality.

As an example plugin, let’s color error messages red:

require 'ripl'

# To try place in ~/.riplrc
module Ripl
  module RedError
    def format_error(error)
      "\e[31m#{super}\e[m"
    end
  end
end
Ripl::Shell.include Ripl::RedError

Note this plugin extends format_error() by invoking the original format_error() with super. This is possible for any method that is available for extension by plugins. To see what methods are available for extension, see Ripl::Shell::API and Ripl::Runner::API.

If we want to add a config for this plugin, we can simply add a key to Ripl.config that matches the underscored version of the plugin name i.e. Ripl.config.

For available plugins, see Ripl Plugins below.

Configuration

Since ripl is highly customizable, it loads ~/.riplrc before it does anything. This ruby file should require and/or define plugins. Any ripl configurations via Ripl.config should also be done here. For an example ~/.riplrc, see mine.

Create Custom Shells

Creating and starting a custom shell is as simple as:

require 'ripl'
# Define plugins, load files, etc...
Ripl.start

Ripl.start takes options to customize your shell. For example if you wanted to start on a specific binding:

Ripl.start :binding => MyClass.instance_eval{ binding }

Create Commands

If you want to invoke your custom shell with ripl, make it a ripl command. To create one, create an executable in the format ripl-<command> and make sure it’s in your shell’s $PATH. For example, the file ripl-my_gem would be invoked with ripl my_gem. Note that with your command you can take arguments and parse your options as you please. For an example command, see ripl-rails.

Credits

  • janlelis and godfat for bug fix and tweaks

  • JoshCheek for bug fixes

  • postmodern for windows fixes and no history support

Bugs/Issues

Please report them on github.

Contributing

See here

Ripl Plugins

Ripl Shells

Shells built on top of ripl:

  • nirvana: A ruby web shell complete with autocomplete

  • fresh: An interesting ruby/system hybrid shell

  • ripl-johnson: A js shell based on johnson (firefox tracemonkey)

  • ronin: An exploit development platform using ripl for its console

  • tux: A sinatra shell

  • rack-webconsole: A rack middleware that adds a web shell to any rack app

Irb Alternatives

Some other irb alternatives to check out:

  • ir: nice and light

  • irb2: yehuda katz’s partial attempt at rewriting irb

  • dietrb: mac and ruby 1.9 specific

  • pry: featureful but heavy

About

ruby interactive print loop - A light, modular alternative to irb

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages