class Mysh::HistoryCommand

The mysh internal history command.

Public Class Methods

new(*args) click to toggle source

Set up this command.

Calls superclass method Mysh::Action::new
# File lib/mysh/internal/history.rb, line 10
def initialize(*args)
  super
  @args = @history = nil
end

Public Instance Methods

process_command(input) click to toggle source

Execute the history command.

# File lib/mysh/internal/history.rb, line 16
def process_command(input)
  @args, @history = input.args, Mysh.input.history

  # The history command should not be part of the history.
  @history.pop

  pull_index || clear_history || show_history
end

Private Instance Methods

clear_history() click to toggle source

Clear the history buffer.

# File lib/mysh/internal/history.rb, line 39
def clear_history
  if @args[0] == 'clear'
    @history.clear
  else
    false
  end
end
pull_index() click to toggle source

Deal with history index arguments

# File lib/mysh/internal/history.rb, line 28
def pull_index
  index = @args[0].to_i

  if (1..@history.length) === index
    Mysh.input.instance_options[:initial] = @history[index-1]
  else
    false
  end
end
show_history() click to toggle source

Just show the history.

# File lib/mysh/internal/history.rb, line 48
def show_history
  pattern = Regexp.new(@args[0] || /./)

  @history.each_with_index do |item, index|
    puts "#{index+1}: #{item}" if item =~ pattern
  end
end