mysh 0.6.12 → 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -3
  3. data/lib/mysh.rb +10 -3
  4. data/lib/mysh/{internal/action.rb → action.rb} +8 -8
  5. data/lib/mysh/{internal/action_pool.rb → action_pool.rb} +8 -8
  6. data/lib/mysh/{internal/actions/command_line.rb → command_line.rb} +10 -10
  7. data/lib/mysh/{internal/actions/command_line → command_line}/debug.rb +0 -0
  8. data/lib/mysh/{internal/actions/command_line → command_line}/history.rb +0 -0
  9. data/lib/mysh/{internal/actions/command_line → command_line}/init.rb +0 -0
  10. data/lib/mysh/{internal/actions/command_line → command_line}/load.rb +0 -0
  11. data/lib/mysh/{internal/actions/command_line → command_line}/pause.rb +0 -0
  12. data/lib/mysh/{internal/actions/command_line → command_line}/post_prompt.rb +0 -0
  13. data/lib/mysh/{internal/actions/command_line → command_line}/pre_prompt.rb +0 -0
  14. data/lib/mysh/{internal/actions/command_line → command_line}/prompt.rb +0 -0
  15. data/lib/mysh/{internal/actions/command_line → command_line}/quit.rb +0 -0
  16. data/lib/mysh/{internal/actions/command_line → command_line}/usage.rb +0 -0
  17. data/lib/mysh/external.rb +3 -4
  18. data/lib/mysh/globalize.rb +5 -7
  19. data/lib/mysh/handlebars.rb +1 -3
  20. data/lib/mysh/handlebars/{string.rb → eval_handlebars.rb} +5 -3
  21. data/lib/mysh/{internal/actions/help → help}/env.txt +0 -0
  22. data/lib/mysh/{internal/actions/help → help}/expr.txt +0 -0
  23. data/lib/mysh/{internal/actions/help → help}/gem.txt +0 -0
  24. data/lib/mysh/{internal/actions/help → help}/gls.txt +0 -0
  25. data/lib/mysh/{internal/actions/help → help}/h_o_h.txt +1 -1
  26. data/lib/mysh/{internal/actions/help → help}/hbar.txt +0 -0
  27. data/lib/mysh/{internal/actions/help → help}/help.txt +0 -0
  28. data/lib/mysh/{internal/actions/help → help}/history.txt +0 -0
  29. data/lib/mysh/{internal/actions/help → help}/init.txt +0 -0
  30. data/lib/mysh/{internal/actions/help → help}/kbd.txt +0 -0
  31. data/lib/mysh/{internal/actions/help → help}/math.txt +0 -0
  32. data/lib/mysh/{internal/actions/help → help}/mls.txt +0 -0
  33. data/lib/mysh/{internal/actions/help → help}/quick.txt +0 -0
  34. data/lib/mysh/{internal/actions/help → help}/ruby.txt +0 -0
  35. data/lib/mysh/{internal/actions/help → help}/show.txt +0 -0
  36. data/lib/mysh/{internal/actions/help → help}/term.txt +0 -0
  37. data/lib/mysh/{internal/actions/help → help}/timed.txt +0 -0
  38. data/lib/mysh/help/type.txt +28 -0
  39. data/lib/mysh/{internal/actions/help → help}/types.txt +0 -0
  40. data/lib/mysh/{internal/actions/help → help}/usage.txt +0 -0
  41. data/lib/mysh/{internal/actions/help → help}/vars.txt +0 -0
  42. data/lib/mysh/input_wrapper.rb +13 -13
  43. data/lib/mysh/internal.rb +20 -8
  44. data/lib/mysh/internal/{actions/cancel.rb → cancel.rb} +0 -0
  45. data/lib/mysh/internal/{actions/cd.rb → cd.rb} +0 -0
  46. data/lib/mysh/internal/{actions/comment.rb → comment.rb} +0 -0
  47. data/lib/mysh/internal/{actions/elapsed.rb → elapsed.rb} +0 -0
  48. data/lib/mysh/internal/{actions/exit.rb → exit.rb} +0 -0
  49. data/lib/mysh/internal/{actions/gls.rb → gls.rb} +0 -0
  50. data/lib/mysh/internal/{actions/help.rb → help.rb} +7 -9
  51. data/lib/mysh/internal/{actions/history.rb → history.rb} +0 -0
  52. data/lib/mysh/internal/load.rb +45 -0
  53. data/lib/mysh/internal/{actions/mls.rb → mls.rb} +0 -0
  54. data/lib/mysh/internal/{actions/pwd.rb → pwd.rb} +0 -0
  55. data/lib/mysh/internal/{actions/say.rb → say.rb} +0 -0
  56. data/lib/mysh/internal/{actions/show.rb → show.rb} +7 -6
  57. data/lib/mysh/internal/{actions/help → support}/sub_help.rb +9 -7
  58. data/lib/mysh/internal/type.rb +38 -0
  59. data/lib/mysh/internal/{actions/vars.rb → vars.rb} +0 -0
  60. data/lib/mysh/{init.rb → load_init_file.rb} +0 -0
  61. data/lib/mysh/process.rb +7 -7
  62. data/lib/mysh/quick.rb +3 -3
  63. data/lib/mysh/shell_variables.rb +6 -3
  64. data/lib/mysh/shell_variables/evaluate.rb +2 -11
  65. data/lib/mysh/{internal/actions/show → show}/env.rb +1 -1
  66. data/lib/mysh/{internal/actions/show → show}/gem.rb +0 -0
  67. data/lib/mysh/{internal/actions/show → show}/ruby.rb +0 -0
  68. data/lib/mysh/{internal/actions/show → show}/term.rb +0 -0
  69. data/lib/mysh/sources/console.rb +3 -2
  70. data/lib/mysh/string_helpers.rb +37 -0
  71. data/lib/mysh/system.rb +2 -2
  72. data/lib/mysh/user_input.rb +4 -7
  73. data/lib/mysh/version.rb +4 -4
  74. data/mysh.gemspec +1 -1
  75. data/tests/my_shell_tests.rb +13 -0
  76. metadata +59 -61
  77. data/lib/mysh/internal/actions/actions_path.rb +0 -15
  78. data/lib/mysh/internal/actions/load.rb +0 -36
  79. data/lib/mysh/internal/actions/type.rb +0 -22
  80. data/lib/mysh/internal/manage.rb +0 -20
  81. data/lib/mysh/internal/to_file_spec.rb +0 -26
  82. data/lib/mysh/pre_processor.rb +0 -11
@@ -1,10 +1,22 @@
1
1
  # coding: utf-8
2
2
 
3
- require_relative 'internal/actions/actions_path'
4
- require_relative 'internal/action'
5
- require_relative 'internal/action_pool'
6
- require_relative 'internal/manage'
7
- require_relative 'internal/to_file_spec'
8
-
9
- #Load up the internal actions!
10
- Dir[Mysh::Action::ACTIONS_PATH + '*.rb'].each {|file| require file }
3
+ module Mysh
4
+
5
+ # Set up the command action pool.
6
+ COMMANDS = ActionPool.new("COMMANDS")
7
+
8
+ # Try to execute the string as an internal action.
9
+ def self.try_execute_internal(input)
10
+ unless input.quick_command == ' '
11
+ if (action = COMMANDS[input.raw_command])
12
+ action.process_command(input)
13
+ :internal
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ # Load up the internal actions!
21
+ load_spec = MYSH_LIB + "mysh/internal/*.rb"
22
+ Dir[load_spec].each {|file| require file }
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/help.rb -- The mysh internal help command.
3
+ # The mysh internal help command.
4
4
  module Mysh
5
5
 
6
6
  # Help action pool of topics.
@@ -21,12 +21,11 @@ module Mysh
21
21
 
22
22
  HELP = ActionPool.new("HELP", default)
23
23
 
24
- #* mysh/internal/actions/help.rb -- The mysh internal help command.
24
+ # The mysh internal help command.
25
25
  class HelpCommand < Action
26
26
 
27
- #Execute a help command by routing it to a sub-command.
28
- #<br>Endemic Code Smells
29
- #* :reek:UtilityFunction
27
+ # Execute a help command by routing it to a sub-command.
28
+ # Endemic Code Smells :reek:UtilityFunction
30
29
  def process_command(input)
31
30
  args = input.args
32
31
  HELP[args[0] || ""].process_command(args)
@@ -37,12 +36,11 @@ module Mysh
37
36
  # The base help command.
38
37
  desc = 'Display help information for mysh with an optional topic. See ?? for more.'
39
38
  COMMANDS.add_action(HelpCommand.new('help <topic>', desc))
39
+
40
40
  #The help command action object.
41
41
  HELP_COMMAND = HelpCommand.new('?<topic>', desc)
42
42
  COMMANDS.add_action(HELP_COMMAND)
43
43
  end
44
44
 
45
- require_relative 'help/sub_help'
46
-
47
- #Load up the extra help actions!
48
- Dir[Mysh::Action::ACTIONS_PATH + 'help/*.rb'].each {|file| require file }
45
+ # Load in support for help sub-topics
46
+ require_relative 'support/sub_help'
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ #* mysh/internal/actions/load.rb -- The mysh load command.
4
+ module Mysh
5
+
6
+ #Add the load command to the library.
7
+ desc = "Load ruby programs, mysh scripts, " +
8
+ "or text files into the mysh environment."
9
+
10
+ action = lambda do |input|
11
+ count = 0
12
+ args = input.args
13
+
14
+ args.each do |file_name|
15
+ puts file_name if args.length > 1
16
+ Mysh.load_a_file(file_name)
17
+ count += 1
18
+ end
19
+
20
+ if count > 0
21
+ :internal
22
+ else
23
+ fail "Error: A load file must be specified."
24
+ end
25
+ end
26
+
27
+ # Load a single file.
28
+ def self.load_a_file(file_name)
29
+ case File.extname(file_name)
30
+ when '.mysh'
31
+ Mysh.process_file(file_name)
32
+ :internal
33
+ when '.txt'
34
+ show_handlebar_file(file_name, binding)
35
+ :internal
36
+ when '.rb'
37
+ load file_name
38
+ :internal
39
+ else
40
+ fail "Error: Unknown file type: #{file_name.inspect}"
41
+ end
42
+ end
43
+
44
+ COMMANDS.add_action(Action.new('load <files>', desc, &action))
45
+ end
@@ -1,19 +1,19 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/show.rb -- The mysh internal show command.
3
+ # The mysh internal show command.
4
4
  module Mysh
5
5
 
6
6
  # The working message for long duration processing.
7
7
  WORKING = "Working...\r"
8
8
 
9
- #Show items.
9
+ # Show items.
10
10
  default = Action.new do |input|
11
11
  puts "No show data found for #{input.raw.inspect}. See ?@ for more."
12
12
  end
13
13
 
14
14
  SHOW = ActionPool.new("SHOW", default)
15
15
 
16
- #The shared description.
16
+ # The shared description.
17
17
  desc = "Display information about a part of mysh. See ?@ for more."
18
18
 
19
19
  action = lambda do |input|
@@ -26,11 +26,12 @@ module Mysh
26
26
  end
27
27
  end
28
28
 
29
- #The show command action object.
29
+ # The show command action object.
30
30
  COMMANDS.add_action(Action.new('show <item>', desc, &action))
31
31
  SHOW_COMMAND = Action.new('@<item>', desc, &action)
32
32
  COMMANDS.add_action(SHOW_COMMAND)
33
33
  end
34
34
 
35
- #Load up the extra help actions!
36
- Dir[Mysh::Action::ACTIONS_PATH + 'show/*.rb'].each {|file| require file }
35
+ # Load up the various show actions!
36
+ path = MYSH_LIB + "mysh/show/*.rb"
37
+ Dir[path].each {|file| require file }
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/help/sub_help.rb -- The mysh internal help sub commands.
3
+ # The mysh internal help sub commands.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/help/sub_help.rb -- The mysh internal help sub commands.
6
+ # The mysh internal help sub commands.
7
7
  class HelpSubCommand < Action
8
8
 
9
- #Setup a help command.
9
+ # Setup a help command.
10
10
  def initialize(name, description, file_name)
11
11
  super(name, description)
12
12
  @file_name = file_name
@@ -14,12 +14,13 @@ module Mysh
14
14
 
15
15
  #Execute a help command.
16
16
  def process_command(_args)
17
- mysh "load #{(ACTIONS_PATH + 'help/' + @file_name).to_host_spec}"
17
+ path = MYSH_LIB + "mysh/help/" + @file_name
18
+ mysh "load #{path.to_host_spec}"
18
19
  end
19
20
 
20
21
  end
21
22
 
22
- #Add help topics here. Don't sweat the order; they get sorted by name.
23
+ # Add help topics here. Don't sweat the order; they get sorted by name.
23
24
  # Name Description Help File
24
25
  help = [['', 'General help on mysh.', 'help.txt' ],
25
26
  ['set', 'Help on mysh variables.', 'vars.txt' ],
@@ -34,13 +35,14 @@ module Mysh
34
35
  ['usage', 'Help on mysh usage.', 'usage.txt' ],
35
36
  ['=', 'Help on ruby expressions.', 'expr.txt' ],
36
37
  ['quick', 'Help on quick commands.', 'quick.txt' ],
37
- ['gls', 'Help on gls internal mysh command.', 'gls.txt' ],
38
- ['mls', 'Help on mls internal mysh command.', 'mls.txt' ],
38
+ ['gls', 'Help on the gls command.', 'gls.txt' ],
39
+ ['mls', 'Help on the mls command.', 'mls.txt' ],
39
40
  ['!', 'Help on the history command.', 'history.txt'],
40
41
  ['history', 'Help on the history command.', 'history.txt'],
41
42
  ['kbd', 'Help on mysh keyboard mapping.', 'kbd.txt' ],
42
43
  ['{{', 'Help on mysh handlebars.', 'hbar.txt' ],
43
44
  ['init', 'Help on mysh initialization.', 'init.txt' ],
45
+ ['type', 'Help on the type command.', 'type.txt' ],
44
46
  ['types', 'Help on mysh file types.', 'types.txt' ],
45
47
  ['help', 'This help on the help command.', 'h_o_h.txt' ],
46
48
  ['?', 'This help on the help command.', 'h_o_h.txt' ]
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ #* mysh/internal/actions/type.rb -- The mysh type command.
4
+ module Mysh
5
+
6
+ #Add the type command to the library.
7
+ desc = 'Display one or more text files with optional support for ' +
8
+ 'embedded handlebars and shell variables. See ?type for more.'
9
+
10
+ action = lambda do |input|
11
+ count = 0
12
+ cooked = MNV[:type] !~ /\A(raw|false|no|off)\z/i
13
+ args = input.args
14
+
15
+ args.each do |file_name|
16
+ puts file_name if args.length > 1
17
+
18
+ case file_name
19
+ when "-c"
20
+ cooked = false
21
+ when "+c"
22
+ cooked = true
23
+ else
24
+ if cooked
25
+ show_handlebar_file(file_name, binding)
26
+ else
27
+ puts IO.read(file_name)
28
+ end
29
+ end
30
+
31
+ count += 1
32
+ end
33
+
34
+ fail "A text file must be specified." if count == 0
35
+ end
36
+
37
+ COMMANDS.add_action(Action.new('type <files>', desc, &action))
38
+ end
File without changes
@@ -1,24 +1,24 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/process.rb -- The mysh command processors.
3
+ # The mysh command processors.
4
4
  module Mysh
5
5
 
6
- #Process from the console.
6
+ # Process from the console.
7
7
  def self.process_console
8
8
  process_source(Console.new)
9
9
  end
10
10
 
11
- #Process from a string.
11
+ # Process from a string.
12
12
  def self.process_string(str)
13
13
  process_source(StringSource.new(str))
14
14
  end
15
15
 
16
- #Process from a file.
16
+ # Process from a file.
17
17
  def self.process_file(name)
18
18
  process_source(StringSource.new(IO.read(name)))
19
19
  end
20
20
 
21
- #Process commands from a source.
21
+ # Process commands from a source.
22
22
  def self.process_source(source)
23
23
  until source.eoi? do
24
24
  execute_a_command(source)
@@ -26,7 +26,7 @@ module Mysh
26
26
  rescue MyshExit
27
27
  end
28
28
 
29
- #Execute a single line of input and handle exceptions.
29
+ # Execute a single line of input and handle exceptions.
30
30
  def self.execute_a_command(source)
31
31
  try_execute_command(get_command(source))
32
32
 
@@ -38,7 +38,7 @@ module Mysh
38
38
  puts err.backtrace if MNV[:debug].extract_boolean || defined?(MiniTest)
39
39
  end
40
40
 
41
- #Try to execute a single line of input. Does not handle exceptions.
41
+ # Try to execute a single line of input. Does not handle exceptions.
42
42
  def self.try_execute_command(str)
43
43
  input = InputWrapper.new(str)
44
44
 
@@ -1,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/quick.rb -- The mysh internal quick commands.
3
+ # The mysh internal quick commands.
4
4
  module Mysh
5
5
 
6
- #A hash of quick command short cuts and their actions.
6
+ # A hash of quick command short cuts and their actions.
7
7
  QUICK = Hash.new(lambda {|_input| false })
8
8
 
9
9
  QUICK['!'] = lambda {|input| HISTORY_COMMAND.process_quick_command(input)}
@@ -19,7 +19,7 @@ module Mysh
19
19
  :expression
20
20
  end
21
21
 
22
- #Try to execute the inputing as a quick command.
22
+ # Try to execute the inputing as a quick command.
23
23
  def self.try_execute_quick(input)
24
24
  QUICK[input.quick_command].call(input)
25
25
  end
@@ -4,13 +4,13 @@ require_relative 'shell_variables/shell_variable_store'
4
4
  require_relative 'shell_variables/shell_variable_keeper'
5
5
  require_relative 'shell_variables/evaluate'
6
6
 
7
- #* mysh/shell_variables.rb -- Adds support for mysh scripting variables.
7
+ # Adds support for mysh scripting variables.
8
8
  module Mysh
9
9
 
10
- #Set up some essential entries.
10
+ # Set up some essential entries.
11
11
  MNV['$'.to_sym] = "$"
12
12
 
13
- #Set up some default values.
13
+ # Set up some default values.
14
14
  MNV[:debug] = "false"
15
15
  MNV[:prompt] = "mysh>"
16
16
  MNV[:post_prompt] = "$prompt"
@@ -22,6 +22,7 @@ module Mysh
22
22
  MNV[:page_msg] = "Press a key, a space, or q:"
23
23
 
24
24
  MNV[:history] = "on"
25
+ MNV[:no_dups] = "on"
25
26
  MNV[:no_move] = "on"
26
27
 
27
28
  MNV[:d] = "{{ Time.now.strftime(MNV[:date_fmt]) }}"
@@ -34,4 +35,6 @@ module Mysh
34
35
 
35
36
  MNV[:date_fmt] = "%Y-%m-%d"
36
37
  MNV[:time_fmt] = "%H:%M"
38
+
39
+ MNV[:type] = "raw"
37
40
  end
@@ -1,18 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #Monkey patches for Mysh variables
3
+ # Monkey patches for Mysh variables
4
4
  class String
5
5
 
6
- #Extract common mysh data from this string.
7
- def extract_boolean
8
- if self =~ /\A(false|no|off)\z/i
9
- false
10
- else
11
- self
12
- end
13
- end
14
-
15
- #Evaluate any variable substitutions in the input.
6
+ # Evaluate any variable substitutions in the string.
16
7
  def eval_variables
17
8
  self.gsub(/((?<!\\)\$\$)|((?<!\\)\$[a-z][a-z0-9_]*)/) do |str|
18
9
  sym = str[1..-1].to_sym
@@ -21,7 +21,7 @@ module Mysh
21
21
  # Get the info
22
22
  # Endemic Code Smells :reek:UtilityFunction
23
23
  def info
24
- [["about", Mysh::SUMMARY],
24
+ [["about", Mysh::DESCRIPTION],
25
25
  ["version", Mysh::VERSION],
26
26
  ["installed", Gem::Specification.find_all_by_name("mysh")
27
27
  .map{|s| s.version.to_s}
@@ -47,8 +47,9 @@ module Mysh
47
47
 
48
48
  # Get some actual user input!
49
49
  def get(parms={})
50
- parms[:history] = MNV[:history].extract_boolean
51
- parms[:no_move] = MNV[:no_move].extract_boolean
50
+ parms[:history] = MNV[:history].extract_boolean unless parms.has_key?(:history)
51
+ parms[:no_dups] = MNV[:no_dups].extract_boolean unless parms.has_key?(:no_dups)
52
+ parms[:no_move] = MNV[:no_move].extract_boolean unless parms.has_key?(:no_move)
52
53
 
53
54
  result = (input = Mysh.input).readline(parms)
54
55
  input.instance_options[:initial] = ""
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ # Monkey patches for Mysh string data.
4
+ class String
5
+
6
+ # Extract Boolean data from this string.
7
+ def extract_boolean
8
+ self !~ /\A(false|no|off)?\z/i
9
+ end
10
+
11
+ # Make the file name fit the local system.
12
+ def to_host_spec
13
+ self.dress_up_slashes
14
+ .dress_up_quotes
15
+ end
16
+
17
+ # Dress up slashes and backslashes.
18
+ def dress_up_slashes
19
+ MiniTerm.windows? ? self.gsub("/", "\\") : self
20
+ end
21
+
22
+ # Dress up in quotes if needed.
23
+ def dress_up_quotes
24
+ self[' '] ? "\"#{self}\"" : self
25
+ end
26
+
27
+ # Make the file name fit the standard notation.
28
+ def to_std_spec
29
+ self.gsub("\\", "/")
30
+ end
31
+
32
+ # The mysh string pre-processor stack.
33
+ def preprocess(evaluator=$mysh_exec_binding)
34
+ self.eval_variables.eval_handlebars(evaluator)
35
+ end
36
+
37
+ end