Description¶ ↑
This ripl plugin provides a core group of commands for any ripl shell. It aims to match and surpass functionality in irb’s commands.
Install¶ ↑
Install the gem with:
sudo gem install ripl-commands
Usage¶ ↑
Add to your ~/.riplrc
require 'ripl/commands'
Try it out:
$ ripl # set any ripl config dynamically >> config :prompt, lambda { "ripl(main):" + Ripl.shell.line.to_s + "> " } => #<Proc:0x0063e2f0@(ripl):1> ripl(main):2> config :result_prompt, '<> ' <> "<> " # Autocomplete available config keys >> config :[TAB] :binding :color_error :multi_line_prompt :name :prompt :result_prompt # Jump around in different objects as irb does with subsessions and workspaces >> jump 'dude' => 'dude' >> self => 'dude' # Autocomplet for the new current object >> cap[TAB] capitalize capitalize! >> capitalize => 'Dude' # To see where you've jumped >> jumps => [main, 'dude'] # Jumping to a number translates to jumping to an existing jump >> jump 0 => main # To list what commands ripl has >> list => ["list", "config", "history", "editor", "jumps", "jump"]
This plugin also comes with commands to see history and prototype code easily in an editor:
# Display last 10 inputs >> history 10 10 : class Porque; def no; 'porque'; end; end 9 : Porque.no 8 : Porque.no 7: %w{can you -dig -this sir?}.inject([]) do |arr, e| 6: if e[/^-/] .. e[/^[^-]/] 5: break(arr) if e[/^[^-]/] 4: arr << e 3: end 2: arr 1: end => ... # Edit last 7 inputs in an editor (specified by ENV['EDITOR']) and eval the edited text >> editor 7 .... => ['dig', '-this'] # If a previous edit exists, opens it in an editor, otherwise opens a new file >> editor
Extending Commands¶ ↑
Extending commands is done by including a module into Ripl::Commands. Say we wanted to extend jumps to look nicer:
# In ~/.riplrc require 'ripl/commands' module Ripl::Commands::NicerJump def jumps super.each_with_index {|e,i| puts "#{i}: #{e.inspect}" } end end Ripl::Commands.send :include, Ripl::Commands::NicerJump
The above jump session then looks like:
>> jumps 0: main 1: "dude"
Credits¶ ↑
-
janlelis for bug fix
-
postmodern for command tweaks
Contributing¶ ↑
Todo¶ ↑
-
Add exit for a jump
-
Fix stacktrace interference caused by jumps