From 8f4844cbf7b9308d3e5165753406c74ccabb54ec Mon Sep 17 00:00:00 2001 From: Rob Gleeson Date: Thu, 5 May 2011 00:45:38 +0100 Subject: [PATCH] Rewrite hist --grep to show index numbers relative to position in history. --- lib/pry/default_commands/input.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index b58f8033..deaadca3 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -17,10 +17,14 @@ class Pry "e.g hist --replay 2..8" opt.on :g, :grep, 'A pattern to match against the history.', true do |pattern| + pattern = Regexp.new pattern history.pop - matches = history.grep Regexp.new(pattern) - text = add_line_numbers matches.join("\n"), 0 - stagger_output text + + history.each_with_index do |element, index| + if element =~ pattern + output.puts "#{colorize index}: #{element}" + end + end end opt.on :r, :replay, 'The line (or range of lines) to replay.', true, :as => Range do |range|