module Mysh

The Mysh (MY SHell) module.

The framework of mysh internal actions.

A managed hash of mysh actions.

The command line options of mysh.

The mysh help command debug.

The mysh command line options for history and no_move.

The mysh init and no-init commands.

The mysh load command.

The mysh post prompt command.

The mysh pre_prompt command.

The mysh prompt command.

The mysh quit command.

The mysh help command usage.

Endemic Code Smells :reek:ModuleInitialize – False positive

Support for executing external files.

An action compatible wrapper for a input.

The mysh internal cancel command.

The mysh internal cd command.

A mysh internal comment.

The mysh internal elapsed command.

The mysh internal exit command.

The mysh gls (gem ls) command.

The mysh internal help command.

The mysh internal history command.

The mysh load command.

The mysh module ls command.

The mysh internal pwd command.

The mysh internal say command.

The mysh internal show command.

The mysh internal help sub commands.

The mysh type command.

The mysh internal variables commands.

The mysh initial file loader.

The mysh command processors.

The mysh internal quick commands.

Adds support for mysh scripting variables.

The keeper of mysh values.

Storage for mysh variables.

Get info on the mysh environment.

Get help on the gem environment.

Get info on the ruby environment.

Get help on the term environment.

The mysh console command source.

mysh general parser.

An adaptive source for auto-complete.

The mysh string command source.

Support for executing through the system.

Get some text from the user.

Constants

COMMANDS

Set up the command action pool.

COMMAND_LINE

Action pool of command line options.

DESCRIPTION

A brief summary of this gem.

E

Set up some popular constants

HELP
HELP_COMMAND

The help command action object.

HISTORY_COMMAND

The history command action object.

MYSH_COMMENT
PI
QUICK

A hash of quick command short cuts and their actions.

SHOW
SHOW_COMMAND
TIMED_COMMAND
USAGE
VERSION

The version string of MY SHell.

WORKING

The working message for long duration processing.

Public Class Methods

execute_a_command(source) click to toggle source

Execute a single line of input and handle exceptions.

# File lib/mysh/process.rb, line 30
def self.execute_a_command(source)
  try_execute_command(get_command(source))

rescue MyshExit
  raise

rescue Interrupt, StandardError, ScriptError => err
  puts "Error #{err.class}: #{err}"
  puts err.backtrace if MNV[:debug].extract_boolean || defined?(MiniTest)
end
get_command(source) click to toggle source

Get one command from the user.

# File lib/mysh/user_input.rb, line 13
def self.get_command(source)
  get_command_extra(source, source.get_command)
end
get_command_extra(source, str) click to toggle source

Get any continuations of the inputs

# File lib/mysh/user_input.rb, line 18
def self.get_command_extra(source, str)
  if str.start_with?("=") && /\\\s*$/ =~ str
    get_command_extra(source, $PREMATCH + "\n" + source.get_command_extra(str))
  else
    str
  end
end
input() click to toggle source

Get the user input ready.

# File lib/mysh/user_input.rb, line 27
def self.input
  @input ||= MiniReadline::Readline.new(eoi_detect:    true,
                                        auto_complete: true,
                                        auto_source:   SmartSource)
end
load_a_file(file_name) click to toggle source

Load a single file.

# File lib/mysh/internal/load.rb, line 28
def self.load_a_file(file_name)
  case File.extname(file_name)
  when '.mysh'
    Mysh.process_file(file_name)
    :internal
  when '.txt'
    show_handlebar_file(file_name, binding)
    :internal
  when '.rb'
    load file_name
    :internal
  else
    fail "Error: Unknown file type: #{file_name.inspect}"
  end
end
mysh_load_init() click to toggle source

Perform initial phase processing.

# File lib/mysh/load_init_file.rb, line 10
def self.mysh_load_init

  unless $mysh_init_file

    if (home = ENV['HOME'])
      names = [home + '/mysh_init.mysh',
               home + '/mysh_init.rb',
               home + '/mysh_init.txt']

      $mysh_init_file = names.detect {|name| File.file?(name)}
    end

    if $mysh_init_file
      mysh "load #{$mysh_init_file.to_host_spec}"
    else
      $mysh_init_file = '<none found>'
    end
  end

end
new() click to toggle source

Set up a new execution environment

# File lib/mysh/expression.rb, line 22
def initialize
  $mysh_exec_binding = binding
end
parse_args(input) click to toggle source

Parse a string into components. Endemic Code Smells :reek:TooManyStatements

# File lib/mysh/sources/parse.rb, line 8
def self.parse_args(input)
  result, read_point = [], input.chars.each

  loop do
    next_parse_char = read_point.next

    if next_parse_char == '"'
      result.concat(get_string(read_point))
    elsif next_parse_char != ' '
      result.concat(get_parameter(next_parse_char, read_point))
    end
  end

  result
end
process_command_args(args, phase) click to toggle source

Execute command line options. Endemic Code Smells :reek:TooManyStatements

# File lib/mysh/command_line.rb, line 33
def self.process_command_args(args, phase)
  read_point = args.each

  loop do
    next_option = read_point.next
    next_command = COMMAND_LINE[next_option]
    raise "Error: Invalid option #{next_option.inspect}" unless next_command
    next_command.send(phase, read_point)
  end

rescue MyshUsage
  HELP["usage"].process_command(nil)
  exit

rescue => err
  more(MNV) do
    puts "", err.to_s, ""
    HELP["usage"].process_command(nil)
  end

  exit
end
process_console() click to toggle source

Process from the console.

# File lib/mysh/process.rb, line 7
def self.process_console
  process_source(Console.new)
end
process_file(name) click to toggle source

Process from a file.

# File lib/mysh/process.rb, line 17
def self.process_file(name)
  process_source(StringSource.new(IO.read(name)))
end
process_source(source) click to toggle source

Process commands from a source.

# File lib/mysh/process.rb, line 22
def self.process_source(source)
  until source.eoi? do
    execute_a_command(source)
  end
rescue MyshExit
end
process_string(str) click to toggle source

Process from a string.

# File lib/mysh/process.rb, line 12
def self.process_string(str)
  process_source(StringSource.new(str))
end
reset_host() click to toggle source

Reset the state of the execution hosting environment. Endemic Code Smells :reek:TooManyStatements – False positive

# File lib/mysh/expression.rb, line 16
def self.reset_host
  exec_class = Class.new do

    include Math

    # Set up a new execution environment
    def initialize
      $mysh_exec_binding = binding
    end

    # Return a simple message for less convoluted error messages.
    def inspect
      "exec_host"
    end

    private

    # Get the previous result
    def result
       $mysh_exec_result
    end

    # Reset the state of the execution host.
    def reset
      Mysh.reset_host
      nil
    end

  end

  $mysh_exec_host = exec_class.new
end
run(args=[]) click to toggle source

The actual shell method.

# File lib/mysh.rb, line 39
def self.run(args=[])
  process_command_args(args, :pre_boot)
  mysh_load_init
  process_command_args(args, :post_boot)

  process_console
end
try_execute_command(str) click to toggle source

Try to execute a single line of input. Does not handle exceptions.

# File lib/mysh/process.rb, line 42
def self.try_execute_command(str)
  input = InputWrapper.new(str)

  more(MNV) do
    try_execute_quick(input)    ||
    try_execute_internal(input) ||
    try_execute_external(input) ||
    try_execute_system(input)
  end
end
try_execute_external(input) click to toggle source

Try to execute an external file. Endemic Code Smells :reek:TooManyStatements

# File lib/mysh/external.rb, line 8
def self.try_execute_external(input)
  args = input.parsed
  file_name = args.shift

  if (file_name)
    ext = File.extname(file_name)

    if ext == '.rb'
      new_command = "#{RbConfig.ruby} #{input.cooked}"
      puts "=> #{new_command}"  if MNV[:debug].extract_boolean
      system(new_command)
      :ruby_exec
    elsif ext == '.mysh'
      Mysh.process_file(file_name)
      :mysh_script
    elsif ext == '.txt'
      show_handlebar_file(file_name, binding)
      :internal
    end
  end
end
try_execute_internal(input) click to toggle source

Try to execute the string as an internal action.

# File lib/mysh/internal.rb, line 9
def self.try_execute_internal(input)
  unless input.quick_command == ' '
    if (action = COMMANDS[input.raw_command])
      action.process_command(input)
      :internal
    end
  end
end
try_execute_quick(input) click to toggle source

Try to execute the inputing as a quick command.

# File lib/mysh/quick.rb, line 23
def self.try_execute_quick(input)
  QUICK[input.quick_command].call(input)
end
try_execute_system(input) click to toggle source

Try to execute as a system program.

# File lib/mysh/system.rb, line 7
def self.try_execute_system(input)
  system(input.raw.preprocess.chomp + "\n") ? :system : :error
end

Private Class Methods

get_parameter(first_char, read_point) click to toggle source

Get a parameter. Endemic Code Smells :reek:TooManyStatements

# File lib/mysh/sources/parse.rb, line 44
def self.get_parameter(first_char, read_point)
  result = first_char

  loop do
    next_parm_char = read_point.next

    if next_parm_char == '"'
      return [result].concat(get_string(read_point))
    elsif next_parm_char == ' '
      break
    else
      result << next_parm_char
    end
  end

  [result]
end
get_string(read_point) click to toggle source

Get a string parameter. Endemic Code Smells :reek:TooManyStatements

# File lib/mysh/sources/parse.rb, line 28
def self.get_string(read_point)
  result = ""

  loop do
    next_str_char = read_point.next

    break if next_str_char == '"'

    result << next_str_char
  end

  [result]
end

Public Instance Methods

inspect() click to toggle source

Return a simple message for less convoluted error messages.

# File lib/mysh/expression.rb, line 27
def inspect
  "exec_host"
end
reset() click to toggle source

Reset the state of the execution host.

# File lib/mysh/expression.rb, line 39
def reset
  Mysh.reset_host
  nil
end
result() click to toggle source

Get the previous result

# File lib/mysh/expression.rb, line 34
def result
   $mysh_exec_result
end