Module: Ripl::Commands::History
- Defined in:
- lib/ripl/commands/history.rb
Class Method Summary collapse
- .edit(last = nil) ⇒ Object
- .editor ⇒ Object
- .history(last = 10) ⇒ Object
- .slice_history(last, start = 1) ⇒ Object
Instance Method Summary collapse
Class Method Details
.edit(last = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ripl/commands/history.rb', line 19 def edit(last=nil) body = if last.nil? && @last_edit @last_edit elsif last.is_a?(Fixnum) start = Array(Ripl.shell.history)[-2][/^history/] ? 2 : 1 slice_history(last, start).join("\n") else '' end file = Tempfile.new('edit_string').path File.open(file, 'w') {|f| f.puts(body) } system(editor, file) Ripl.shell.loop_eval(@last_edit = File.read(file)) end |
.editor ⇒ Object
34 35 36 |
# File 'lib/ripl/commands/history.rb', line 34 def editor ENV['EDITOR'] ? ENV['EDITOR'][/\w+/] : 'vim' end |
.history(last = 10) ⇒ Object
13 14 15 16 17 |
# File 'lib/ripl/commands/history.rb', line 13 def history(last=10) slice_history(last).each_with_index do |e,i| puts "#{last - i}: #{e}" end end |
.slice_history(last, start = 1) ⇒ Object
38 39 40 |
# File 'lib/ripl/commands/history.rb', line 38 def slice_history(last, start=1) Array(Ripl.shell.history).reverse.slice(start, last).reverse end |