Module: Mysh
- Defined in:
- lib/mysh.rb,
lib/mysh/quick.rb,
lib/mysh/action.rb,
lib/mysh/system.rb,
lib/mysh/process.rb,
lib/mysh/version.rb,
lib/mysh/external.rb,
lib/mysh/internal.rb,
lib/mysh/show/env.rb,
lib/mysh/show/gem.rb,
lib/mysh/show/ruby.rb,
lib/mysh/show/term.rb,
lib/mysh/expression.rb,
lib/mysh/user_input.rb,
lib/mysh/action_pool.rb,
lib/mysh/internal/cd.rb,
lib/mysh/command_line.rb,
lib/mysh/internal/gls.rb,
lib/mysh/internal/mls.rb,
lib/mysh/internal/pwd.rb,
lib/mysh/internal/say.rb,
lib/mysh/input_wrapper.rb,
lib/mysh/internal/exit.rb,
lib/mysh/internal/help.rb,
lib/mysh/internal/load.rb,
lib/mysh/internal/show.rb,
lib/mysh/internal/type.rb,
lib/mysh/internal/vars.rb,
lib/mysh/sources/parse.rb,
lib/mysh/load_init_file.rb,
lib/mysh/sources/string.rb,
lib/mysh/internal/cancel.rb,
lib/mysh/shell_variables.rb,
lib/mysh/sources/console.rb,
lib/mysh/internal/comment.rb,
lib/mysh/internal/elapsed.rb,
lib/mysh/internal/history.rb,
lib/mysh/command_line/init.rb,
lib/mysh/command_line/load.rb,
lib/mysh/command_line/quit.rb,
lib/mysh/command_line/debug.rb,
lib/mysh/command_line/pause.rb,
lib/mysh/command_line/usage.rb,
lib/mysh/command_line/prompt.rb,
lib/mysh/command_line/history.rb,
lib/mysh/command_line/pre_prompt.rb,
lib/mysh/command_line/post_prompt.rb,
lib/mysh/internal/support/sub_help.rb,
lib/mysh/sources/smart_auto_complete.rb,
lib/mysh/shell_variables/shell_variable_store.rb,
lib/mysh/shell_variables/shell_variable_keeper.rb
Overview
The keeper of mysh values.
Defined Under Namespace
Modules: MNV Classes: Action, ActionPool, CommandOption, Console, DebugOption, DoMoveHistoryOption, EnvInfoCommand, GemInfoCommand, GlsCommand, HelpCommand, HelpSubCommand, HistoryCommand, HistoryOption, InitOption, InputWrapper, Keeper, LoadOption, NoDebugOption, NoHistoryOption, NoInitOption, NoMoveHistoryOption, NoPauseOption, NoPostpromptOption, NoPrepromptOption, NoPromptOption, PauseOption, PostpromptOption, PrepromptOption, PromptOption, QuitOption, RubyInfoCommand, SmartSource, StringSource, TermInfoCommand, UsageOption, VarsCommand
Constant Summary collapse
- QUICK =
A hash of quick command short cuts and their actions.
Hash.new(lambda {|_input| false })
- VERSION =
The version string of MY SHell.
"0.6.14".freeze
- DESCRIPTION =
A brief summary of this gem.
"mysh -- a Ruby inspired command line shell.".freeze
- COMMANDS =
Set up the command action pool.
ActionPool.new("COMMANDS")
- E =
Set up some popular constants
Math::E
- PI =
Math::PI
- COMMAND_LINE =
Action pool of command line options.
ActionPool.new("COMMAND_LINE")
- HELP =
ActionPool.new("HELP", default)
- HELP_COMMAND =
The help command action object.
HelpCommand.new('?<topic>', desc)
- WORKING =
The working message for long duration processing.
"Working...\r"
- SHOW =
ActionPool.new("SHOW", default)
- SHOW_COMMAND =
Action.new('@<item>', desc, &action)
- MYSH_COMMENT =
Action.new('#<stuff>', desc, &action)
- TIMED_COMMAND =
Action.new('%<command>', desc, &action)
- HISTORY_COMMAND =
The history command action object.
HistoryCommand.new('!<arg>', desc)
- USAGE =
UsageOption.new('--help', desc)
Class Method Summary collapse
-
.execute_a_command(source) ⇒ Object
Execute a single line of input and handle exceptions.
-
.get_command(source) ⇒ Object
Get one command from the user.
-
.get_command_extra(source, str) ⇒ Object
Get any continuations of the inputs.
-
.input ⇒ Object
Get the user input ready.
-
.load_a_file(file_name) ⇒ Object
Load a single file.
-
.mysh_load_init ⇒ Object
Perform initial phase processing.
-
.parse_args(input) ⇒ Object
Parse a string into components.
-
.process_command_args(args, phase) ⇒ Object
Execute command line options.
-
.process_console ⇒ Object
Process from the console.
-
.process_file(name) ⇒ Object
Process from a file.
-
.process_source(source) ⇒ Object
Process commands from a source.
-
.process_string(str) ⇒ Object
Process from a string.
-
.reset_host ⇒ Object
Reset the state of the execution hosting environment.
-
.run(args = []) ⇒ Object
The actual shell method.
-
.try_execute_command(str) ⇒ Object
Try to execute a single line of input.
-
.try_execute_external(input) ⇒ Object
Try to execute an external file.
-
.try_execute_internal(input) ⇒ Object
Try to execute the string as an internal action.
-
.try_execute_quick(input) ⇒ Object
Try to execute the inputing as a quick command.
-
.try_execute_system(input) ⇒ Object
Try to execute as a system program.
Class Method Details
.execute_a_command(source) ⇒ Object
Execute a single line of input and handle exceptions.
30 31 32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
Get one command from the user.
13 14 15 |
# 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) ⇒ Object
Get any continuations of the inputs
18 19 20 21 22 23 24 |
# 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 ⇒ Object
Get the user input ready.
27 28 29 30 31 |
# 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) ⇒ Object
Load a single file.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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' (file_name, binding) :internal when '.rb' load file_name :internal else fail "Error: Unknown file type: #{file_name.inspect}" end end |
.mysh_load_init ⇒ Object
Perform initial phase processing.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
.parse_args(input) ⇒ Object
Parse a string into components. Endemic Code Smells :reek:TooManyStatements
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
Execute command line options. Endemic Code Smells :reek:TooManyStatements
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
Process from the console.
7 8 9 |
# File 'lib/mysh/process.rb', line 7 def self.process_console process_source(Console.new) end |
.process_file(name) ⇒ Object
Process from a file.
17 18 19 |
# File 'lib/mysh/process.rb', line 17 def self.process_file(name) process_source(StringSource.new(IO.read(name))) end |
.process_source(source) ⇒ Object
Process commands from a source.
22 23 24 25 26 27 |
# 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) ⇒ Object
Process from a string.
12 13 14 |
# File 'lib/mysh/process.rb', line 12 def self.process_string(str) process_source(StringSource.new(str)) end |
.reset_host ⇒ Object
Reset the state of the execution hosting environment. Endemic Code Smells :reek:TooManyStatements – False positive
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 = []) ⇒ Object
The actual shell method.
39 40 41 42 43 44 45 |
# 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) ⇒ Object
Try to execute a single line of input. Does not handle exceptions.
42 43 44 45 46 47 48 49 50 51 |
# 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) ⇒ Object
Try to execute an external file. Endemic Code Smells :reek:TooManyStatements
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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' (file_name, binding) :internal end end end |
.try_execute_internal(input) ⇒ Object
Try to execute the string as an internal action.
9 10 11 12 13 14 15 16 |
# 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) ⇒ Object
Try to execute the inputing as a quick command.
23 24 25 |
# File 'lib/mysh/quick.rb', line 23 def self.try_execute_quick(input) QUICK[input.quick_command].call(input) end |
.try_execute_system(input) ⇒ Object
Try to execute as a system program.
7 8 9 |
# File 'lib/mysh/system.rb', line 7 def self.try_execute_system(input) system(input.raw.preprocess.chomp + "\n") ? :system : :error end |