2011-05-01 10:25:37 +00:00
|
|
|
class Pry
|
|
|
|
module DefaultCommands
|
|
|
|
|
|
|
|
Input = Pry::CommandSet.new :input do
|
|
|
|
|
|
|
|
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do
|
|
|
|
output.puts "Input buffer cleared!"
|
|
|
|
opts[:eval_string].clear
|
|
|
|
end
|
|
|
|
|
|
|
|
command "hist", "Show and replay Readline history. Type `hist --help` for more info." do |*args|
|
2011-05-04 17:41:02 +00:00
|
|
|
history = Readline::HISTORY.to_a
|
2011-05-01 10:25:37 +00:00
|
|
|
|
2011-05-04 17:41:02 +00:00
|
|
|
Slop.parse(args) do |opt|
|
|
|
|
opt.banner "Usage: hist [--replay START..END]\n" \
|
|
|
|
"View and replay history\n" \
|
|
|
|
"e.g hist --replay 2..8"
|
|
|
|
|
2011-05-04 18:26:27 +00:00
|
|
|
opt.on :g, :grep, 'A pattern to match against the history.', true do |pattern|
|
|
|
|
history.pop
|
|
|
|
matches = history.grep Regexp.new(pattern)
|
|
|
|
text = add_line_numbers matches.join("\n"), 0
|
|
|
|
stagger_output text
|
|
|
|
end
|
|
|
|
|
2011-05-04 18:46:49 +00:00
|
|
|
opt.on :r, :replay, 'The line (or range of lines) to replay.', true, :as => Range do |range|
|
|
|
|
unless opt.g?
|
|
|
|
actions = history[range].join("\n") + "\n"
|
|
|
|
Pry.active_instance.input = StringIO.new(actions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
opt.on :c, :clear, 'Clear the history' do
|
|
|
|
unless opt.g?
|
|
|
|
Readline::HISTORY.clear
|
|
|
|
output.puts 'History cleared.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-01 10:25:37 +00:00
|
|
|
opt.on :h, :help, 'Show this message.', :tail => true do
|
2011-05-04 18:46:49 +00:00
|
|
|
unless opt.g?
|
|
|
|
output.puts opt.help
|
|
|
|
end
|
2011-05-01 10:25:37 +00:00
|
|
|
end
|
2011-05-04 17:55:34 +00:00
|
|
|
|
|
|
|
opt.on_empty do
|
|
|
|
text = add_line_numbers history.join("\n"), 0
|
|
|
|
stagger_output text
|
|
|
|
end
|
2011-05-01 10:25:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|