From 933ce7b355c056f1c23cc37f2a2156e3ae01958a Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 5 May 2011 22:06:56 +1200 Subject: [PATCH] added first stab at amend-line, works to modify previous line in eval_string, also added more file types to Rakefile clean task --- Rakefile | 3 ++- lib/pry/default_commands/input.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index fe48d3a6..43949494 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,8 @@ $:.unshift 'lib' require 'pry/version' CLOBBER.include("**/*~", "**/*#*", "**/*.log") -CLEAN.include("**/*#*", "**/*#*.*", "**/*_flymake*.*", "**/*_flymake", "**/*.rbc") +CLEAN.include("**/*#*", "**/*#*.*", "**/*_flymake*.*", "**/*_flymake", + "**/*.rbc", "**/.#*.*") def apply_spec_defaults(s) s.name = "pry" diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index b0c95131..95b39ef3 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -8,6 +8,14 @@ class Pry opts[:eval_string].clear end + command "amend-line", "Amend the previous line of input." do |replacement_line| + replacement_line = "" if !replacement_line + input_array = opts[:eval_string].each_line.to_a[0..-2] + [remove_first_word(opts[:val]) + "\n"] + opts[:eval_string].replace input_array.join("\n") + end + + alias_command "%", "amend-line" + command "hist", "Show and replay Readline history. Type `hist --help` for more info." do |*args| history = Readline::HISTORY.to_a @@ -17,7 +25,7 @@ class Pry opt.on :g, :grep, 'A pattern to match against the history.', true do |pattern| pattern = Regexp.new pattern history.pop - + history.each_with_index do |element, index| if element =~ pattern output.puts "#{colorize index}: #{element}"