Module: Mysh

Defined in:
lib/mysh.rb,
lib/mysh/ruby.rb,
lib/mysh/version.rb,
lib/mysh/expression.rb,
lib/mysh/commands/cd.rb,
lib/mysh/smart_source.rb,
lib/mysh/commands/exit.rb,
lib/mysh/commands/help.rb,
lib/mysh/internal/klass.rb,
lib/mysh/internal/parse.rb,
lib/mysh/commands/history.rb,
lib/mysh/internal/decorate.rb,
lib/mysh/internal/instance.rb

Overview

  • internal.rb – mysh internal command instance data and methods.

Defined Under Namespace

Classes: ExecHost, InternalCommand, SmartSource

Constant Summary collapse

VERSION =

The version string of MY SHell.

"0.1.8"
SUMMARY =

A brief summary of this gem.

"mysh -- a Ruby inspired command shell"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.inputObject (readonly)

The input text source.


20
21
22
# File 'lib/mysh.rb', line 20

def input
  @input
end

Class Method Details

.init_runObject

Set up for the run command.


46
47
48
49
50
51
52
# File 'lib/mysh.rb', line 46

def self.init_run
  reset_host
  @input = MiniReadline::Readline.new(history: true,
                                      eoi_detect: true,
                                      auto_complete: true,
                                      auto_source: SmartSource)
end

.reset_hostObject

Reset the state of the execution hosting environment.


55
56
57
# File 'lib/mysh.rb', line 55

def self.reset_host
  @exec_host = ExecHost.new
end

.ruby_execute(str) ⇒ Object

Try to execute as a Ruby program.


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mysh/ruby.rb', line 6

def self.ruby_execute(str)
  if File.extname(str.split[0]) == '.rb'
    new_command = "ruby #{str}"

    puts "=> #{new_command}"
    puts

    system(new_command)
    :ruby_exec
  end

end

.runObject

The actual shell method.
Endemic Code Smells

  • :reek:TooManyStatements


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mysh.rb', line 26

def self.run
  init_run

  loop do
    input = @input.readline(prompt: 'mysh> ')

    begin
      @exec_host.execute(input)      ||
      InternalCommand.execute(input) ||
      ruby_execute(input)            ||
      system(input)
    rescue Interrupt => err
      puts err
    end
  end

  rescue Interrupt, MiniReadlineEOI
end