mysh 0.6.11 → 0.6.17

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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -3
  3. data/lib/mysh.rb +15 -6
  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 +9 -11
  8. data/lib/mysh/command_line/history.rb +61 -0
  9. data/lib/mysh/{internal/actions/command_line → command_line}/init.rb +8 -8
  10. data/lib/mysh/{internal/actions/command_line → command_line}/load.rb +5 -5
  11. data/lib/mysh/{internal/actions/command_line → command_line}/pause.rb +6 -8
  12. data/lib/mysh/{internal/actions/command_line → command_line}/post_prompt.rb +10 -12
  13. data/lib/mysh/{internal/actions/command_line → command_line}/pre_prompt.rb +10 -12
  14. data/lib/mysh/{internal/actions/command_line → command_line}/prompt.rb +9 -10
  15. data/lib/mysh/command_line/quit.rb +19 -0
  16. data/lib/mysh/{internal/actions/command_line → command_line}/usage.rb +4 -4
  17. data/lib/mysh/external.rb +3 -4
  18. data/lib/mysh/globalize.rb +5 -14
  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 +7 -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 +4 -4
  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} +2 -2
  46. data/lib/mysh/internal/{actions/comment.rb → comment.rb} +2 -2
  47. data/lib/mysh/internal/{actions/elapsed.rb → elapsed.rb} +2 -2
  48. data/lib/mysh/internal/{actions/exit.rb → exit.rb} +0 -0
  49. data/lib/mysh/internal/{actions/gls.rb → gls.rb} +6 -7
  50. data/lib/mysh/internal/{actions/help.rb → help.rb} +7 -9
  51. data/lib/mysh/internal/{actions/history.rb → history.rb} +10 -9
  52. data/lib/mysh/internal/load.rb +45 -0
  53. data/lib/mysh/internal/{actions/mls.rb → mls.rb} +2 -2
  54. data/lib/mysh/internal/{actions/pwd.rb → pwd.rb} +1 -1
  55. data/lib/mysh/internal/{actions/say.rb → say.rb} +1 -1
  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} +8 -8
  60. data/lib/mysh/{init.rb → load_init_file.rb} +3 -3
  61. data/lib/mysh/process.rb +7 -7
  62. data/lib/mysh/quick.rb +3 -3
  63. data/lib/mysh/shell_variables.rb +9 -4
  64. data/lib/mysh/shell_variables/evaluate.rb +2 -11
  65. data/lib/mysh/shell_variables/shell_variable_keeper.rb +6 -7
  66. data/lib/mysh/shell_variables/shell_variable_store.rb +13 -14
  67. data/lib/mysh/{internal/actions/show → show}/env.rb +1 -1
  68. data/lib/mysh/{internal/actions/show → show}/gem.rb +0 -0
  69. data/lib/mysh/{internal/actions/show → show}/ruby.rb +0 -0
  70. data/lib/mysh/{internal/actions/show → show}/term.rb +0 -0
  71. data/lib/mysh/sources/console.rb +11 -7
  72. data/lib/mysh/sources/parse.rb +7 -10
  73. data/lib/mysh/sources/smart_auto_complete.rb +5 -5
  74. data/lib/mysh/sources/string.rb +6 -6
  75. data/lib/mysh/string_helpers.rb +37 -0
  76. data/lib/mysh/system.rb +2 -2
  77. data/lib/mysh/user_input.rb +5 -9
  78. data/lib/mysh/version.rb +4 -4
  79. data/mysh.gemspec +5 -4
  80. data/tests/my_shell_tests.rb +13 -0
  81. metadata +81 -68
  82. data/lib/mysh/internal/actions/actions_path.rb +0 -15
  83. data/lib/mysh/internal/actions/command_line/quit.rb +0 -19
  84. data/lib/mysh/internal/actions/load.rb +0 -36
  85. data/lib/mysh/internal/actions/type.rb +0 -22
  86. data/lib/mysh/internal/manage.rb +0 -20
  87. data/lib/mysh/internal/to_file_spec.rb +0 -26
  88. data/lib/mysh/pre_processor.rb +0 -11
@@ -5,9 +5,8 @@ module Mysh
5
5
  # The page pause option.
6
6
  class PauseOption < CommandOption
7
7
 
8
- #Execute the help command line option.
9
- #<br>Endemic Code Smells
10
- #* :reek:UtilityFunction
8
+ # Execute the help command line option.
9
+ # Endemic Code Smells :reek:UtilityFunction
11
10
  def post_boot(_args)
12
11
  MNV[:page_pause] = "on"
13
12
  end
@@ -18,16 +17,15 @@ module Mysh
18
17
 
19
18
  end
20
19
 
21
- #Add the pause command line option to the library.
20
+ # Add the pause command line option to the library.
22
21
  desc = 'Turn on page pauses.'
23
22
  COMMAND_LINE.add_action(PauseOption.new('--pause', desc))
24
23
 
25
24
  # The no page pause option.
26
25
  class NoPauseOption < CommandOption
27
26
 
28
- #Execute the help command line option.
29
- #<br>Endemic Code Smells
30
- #* :reek:UtilityFunction
27
+ # Execute the help command line option.
28
+ # Endemic Code Smells :reek:UtilityFunction
31
29
  def post_boot(_args)
32
30
  MNV[:page_pause] = "off"
33
31
  end
@@ -38,7 +36,7 @@ module Mysh
38
36
 
39
37
  end
40
38
 
41
- #Add the no pause command line option to the library.
39
+ # Add the no pause command line option to the library.
42
40
  desc = 'Turn off page pauses.'
43
41
  COMMAND_LINE.add_action(NoPauseOption.new('--no-pause', desc))
44
42
  end
@@ -1,43 +1,41 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/command_line/prompt.rb -- The mysh post prompt command.
3
+ # The mysh post prompt command.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/command_line/post_prompt.rb -- The mysh post prompt command.
6
+ # The mysh post prompt command.
7
7
  class PostpromptOption < CommandOption
8
8
 
9
- #Skip over the argument for pre_boot.
9
+ # Skip over the argument for pre_boot.
10
10
  def pre_boot(read_point)
11
11
  get_arg(read_point)
12
12
  end
13
13
 
14
- #Execute the prompt command line option.
15
- #<br>Endemic Code Smells
16
- #* :reek:UtilityFunction
14
+ # Execute the prompt command line option.
15
+ # Endemic Code Smells :reek:UtilityFunction
17
16
  def post_boot(read_point)
18
17
  MNV[:post_prompt] = get_arg(read_point)
19
18
  end
20
19
 
21
20
  end
22
21
 
23
- #Add the post prompt command line option to the library.
22
+ # Add the post prompt command line option to the library.
24
23
  desc = 'Set the mysh line continuation prompt to "str".'
25
24
  COMMAND_LINE.add_action(PostpromptOption.new('--post-prompt "str"', desc))
26
25
  COMMAND_LINE.add_action(PostpromptOption.new('-pp "str"', desc))
27
26
 
28
- #* mysh/internal/actions/command_line/post_prompt.rb -- The mysh command no post prompt.
27
+ # The mysh command no post prompt.
29
28
  class NoPostpromptOption < CommandOption
30
29
 
31
- #Execute the no post prompt command line option.
32
- #<br>Endemic Code Smells
33
- #* :reek:UtilityFunction
30
+ # Execute the no post prompt command line option.
31
+ # Endemic Code Smells :reek:UtilityFunction
34
32
  def post_boot(_args)
35
33
  MNV[:post_prompt] = ""
36
34
  end
37
35
 
38
36
  end
39
37
 
40
- #Add the prompt command line option to the library.
38
+ # Add the prompt command line option to the library.
41
39
  desc = 'Turn off mysh post prompting.'
42
40
  COMMAND_LINE.add_action(NoPostpromptOption.new('--no-post-prompt', desc))
43
41
  COMMAND_LINE.add_action(NoPostpromptOption.new('-npp', desc))
@@ -1,43 +1,41 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/command_line/prompt.rb -- The mysh pre_prompt command.
3
+ # The mysh pre_prompt command.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/command_line/pre_prompt.rb -- The mysh pre_prompt command.
6
+ # The mysh pre_prompt command.
7
7
  class PrepromptOption < CommandOption
8
8
 
9
- #Skip over the argument for pre_boot.
9
+ # Skip over the argument for pre_boot.
10
10
  def pre_boot(read_point)
11
11
  get_arg(read_point)
12
12
  end
13
13
 
14
- #Execute the prompt command line option.
15
- #<br>Endemic Code Smells
16
- #* :reek:UtilityFunction
14
+ # Execute the prompt command line option.
15
+ # Endemic Code Smells :reek:UtilityFunction
17
16
  def post_boot(read_point)
18
17
  MNV[:pre_prompt] = get_arg(read_point)
19
18
  end
20
19
 
21
20
  end
22
21
 
23
- #Add the pre prompt command line option to the library.
22
+ # Add the pre prompt command line option to the library.
24
23
  desc = 'Set the mysh pre prompt to "str".'
25
24
  COMMAND_LINE.add_action(PrepromptOption.new('--pre-prompt "str"', desc))
26
25
  COMMAND_LINE.add_action(PrepromptOption.new('-pr "str"', desc))
27
26
 
28
- #* mysh/internal/actions/command_line/pre_prompt.rb -- The mysh command no pre_prompt.
27
+ # The mysh command no pre_prompt.
29
28
  class NoPrepromptOption < CommandOption
30
29
 
31
- #Execute the no pre_prompt command line option.
32
- #<br>Endemic Code Smells
33
- #* :reek:UtilityFunction
30
+ # Execute the no pre_prompt command line option.
31
+ # Endemic Code Smells :reek:UtilityFunction
34
32
  def post_boot(_args)
35
33
  MNV[:pre_prompt] = ""
36
34
  end
37
35
 
38
36
  end
39
37
 
40
- #Add the prompt command line option to the library.
38
+ # Add the prompt command line option to the library.
41
39
  desc = 'Turn off mysh pre prompting.'
42
40
  COMMAND_LINE.add_action(NoPrepromptOption.new('--no-pre-prompt', desc))
43
41
  COMMAND_LINE.add_action(NoPrepromptOption.new('-npr', desc))
@@ -1,41 +1,40 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/command_line/prompt.rb -- The mysh prompt command.
3
+ # The mysh prompt command.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/command_line/prompt.rb -- The mysh prompt command.
6
+ # The mysh prompt command.
7
7
  class PromptOption < CommandOption
8
8
 
9
- #Skip over the argument for pre_boot.
9
+ # Skip over the argument for pre_boot.
10
10
  def pre_boot(read_point)
11
11
  get_arg(read_point)
12
12
  end
13
13
 
14
- #Execute the prompt command line option.
14
+ # Execute the prompt command line option.
15
15
  def post_boot(read_point)
16
16
  MNV[:prompt] = get_arg(read_point)
17
17
  end
18
18
 
19
19
  end
20
20
 
21
- #Add the prompt command line option to the library.
21
+ # Add the prompt command line option to the library.
22
22
  desc = 'Set the mysh prompt to "str".'
23
23
  COMMAND_LINE.add_action(PromptOption.new('--prompt "str"', desc))
24
24
  COMMAND_LINE.add_action(PromptOption.new('-p "str"', desc))
25
25
 
26
- #* mysh/internal/actions/command_line/prompt.rb -- The mysh prompt command no prompt.
26
+ # The mysh prompt command no prompt.
27
27
  class NoPromptOption < CommandOption
28
28
 
29
- #Execute the no prompt command line option.
30
- #<br>Endemic Code Smells
31
- #* :reek:UtilityFunction
29
+ # Execute the no prompt command line option.
30
+ # Endemic Code Smells :reek:UtilityFunction
32
31
  def post_boot(_args)
33
32
  MNV[:prompt] = ""
34
33
  end
35
34
 
36
35
  end
37
36
 
38
- #Add the prompt command line option to the library.
37
+ # Add the prompt command line option to the library.
39
38
  desc = 'Turn off mysh prompting.'
40
39
  COMMAND_LINE.add_action(NoPromptOption.new('--no-prompt', desc))
41
40
  COMMAND_LINE.add_action(NoPromptOption.new('-np', desc))
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ # The mysh quit command.
4
+ module Mysh
5
+
6
+ # The mysh quit command.
7
+ class QuitOption < CommandOption
8
+
9
+ # Execute the quit command line option.
10
+ def post_boot(_args)
11
+ exit
12
+ end
13
+
14
+ end
15
+
16
+ # Add the quit command line option to the library.
17
+ desc = "Exit a nested mysh file or command."
18
+ COMMAND_LINE.add_action(QuitOption.new('--quit', desc))
19
+ end
@@ -1,19 +1,19 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/command_line/usage.rb -- The mysh help command usage.
3
+ # The mysh help command usage.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/command_line/usage.rb -- The mysh help command usage.
6
+ # The mysh help command usage.
7
7
  class UsageOption < CommandOption
8
8
 
9
- #Execute the help command line option. (Punt to error handler with no msg)
9
+ # Execute the help command line option. (Punt to error handler with no msg)
10
10
  def pre_boot(_args)
11
11
  raise MyshUsage
12
12
  end
13
13
 
14
14
  end
15
15
 
16
- #Add the usage command line option to the library.
16
+ # Add the usage command line option to the library.
17
17
  desc = 'Display mysh usage info and exit.'
18
18
 
19
19
  USAGE = UsageOption.new('--help', desc)
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/external.rb -- Support for executing external files.
3
+ # Support for executing external files.
4
4
  module Mysh
5
5
 
6
- #Try to execute an external file.
7
- #<br>Endemic Code Smells
8
- #* :reek:TooManyStatements
6
+ # Try to execute an external file.
7
+ # Endemic Code Smells :reek:TooManyStatements
9
8
  def self.try_execute_external(input)
10
9
  args = input.parsed
11
10
  file_name = args.shift
@@ -1,16 +1,15 @@
1
1
  # coding: utf-8
2
2
 
3
- #Monkey patches for mysh global entities.
3
+ # Monkey patches for mysh global entities.
4
4
  class Object
5
5
 
6
- #Make the environment variable store accessible everywhere.
6
+ # Make the environment variable store accessible everywhere.
7
7
  MNV = Mysh::MNV
8
8
 
9
9
  private
10
10
 
11
- #The mysh equivalent of the system method.
12
- #<br>Endemic Code Smells
13
- #* :reek:UtilityFunction
11
+ # The mysh equivalent of the system method.
12
+ # Endemic Code Smells :reek:UtilityFunction
14
13
  def mysh(str)
15
14
  Mysh.try_execute_command(str)
16
15
  end
@@ -20,21 +19,13 @@ class Object
20
19
  raise MyshExit
21
20
  end
22
21
 
23
- # Run some code with no wuccas.
24
- def insouciant
25
- yield
26
- rescue => err
27
- err.to_s
28
- end
29
-
30
22
  # Get the latest version for the named gem. Patched code.
31
23
  def latest_version_for(name, fetcher=nil)
32
24
  dependency = Gem::Dependency.new(name)
33
25
  fetcher ||= Gem::SpecFetcher.new
34
26
 
35
27
  if specs = fetcher.spec_for_dependency(dependency)[0][-1]
36
- spec = specs[0]
37
- spec && spec.version
28
+ specs[0].version
38
29
  else
39
30
  "<Not found in repository>"
40
31
  end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- require_relative 'handlebars/string'
3
+ require_relative 'handlebars/eval_handlebars'
4
4
 
5
5
  # Handlebar embedded ruby support.
6
6
  class Object
@@ -21,5 +21,3 @@ private
21
21
  end
22
22
 
23
23
  end
24
-
25
-
@@ -7,14 +7,15 @@ class String
7
7
  def eval_handlebars(evaluator=$mysh_exec_binding)
8
8
  string, text, buffer = self, "", []
9
9
 
10
+ # Translate the string with embedded code into Ruby code.
10
11
  until string.empty?
11
12
  text, code, string = string.partition(/{{.*?}}/m)
12
13
 
13
- if not text.empty?
14
+ unless text.empty?
14
15
  text = text.gsub(/\\[{}]/) {|found| found[1]}
15
16
  buffer << "_m_<<#{text.inspect};"
16
- elsif buffer.empty?
17
- buffer << ""
17
+ else
18
+ buffer << "" if buffer.empty?
18
19
  end
19
20
 
20
21
  unless code.empty?
@@ -26,6 +27,7 @@ class String
26
27
  end
27
28
  end
28
29
 
30
+ # Evaluate the result of the translation.
29
31
  if buffer.length > 1
30
32
  evaluator.eval("_m_ = '';" + buffer.join + "_m_")
31
33
  else
@@ -14,7 +14,7 @@ Brief summaries are also available on the following internal commands:
14
14
 
15
15
  {{ Mysh::COMMANDS.actions_info
16
16
  .reject{|cmd| cmd[1]["See ?"]}
17
- .map{|cmd| cmd[0].split[0] }
17
+ .map{|cmd| cmd[0].gsub(/<.*>/, "").strip }
18
18
  .join(" ")
19
19
  }}
20
20
 
@@ -21,3 +21,10 @@ Form Form Description
21
21
  regex pattern. Note: This pattern cannot be 'clear'
22
22
  so use 'clea[r]' instead.
23
23
 
24
+ The history buffer is controlled by two variables:
25
+
26
+ $$history Is the history buffer enabled?
27
+ $$no_move Are history entries kept in place or shifted up the buffer?
28
+
29
+ These are also controlled by command line options. See ?usage for more info.
30
+
@@ -0,0 +1,28 @@
1
+ Help: mysh type command summary:
2
+
3
+ The type command is used to display one or more text files. The names of these
4
+ files are the arguments to this command as are options that control how those
5
+ files are processed before being displayed.
6
+
7
+ Files can be handled in one of two modes:
8
+
9
+ raw Files are displayed with no pre-processing
10
+ cooked Files are displayed after handlebars and shell variables have been
11
+ processed and the results inserted into the text.
12
+
13
+ The default behavior of the type command is set by the \$type variable. This
14
+ may take the values:
15
+
16
+ raw, off, false, no = raw mode (the default value)
17
+ cooked, on, true, yes = cooked mode
18
+
19
+ Within the type command, options can be used to override the defaults:
20
+
21
+ +c Force cooked mode.
22
+ -c Force raw mode.
23
+
24
+ Note: This command contrasts with the load command which can also be used to
25
+ display text files. The difference is the the load command always expands
26
+ handlebars and shell variables.
27
+
28
+
@@ -4,7 +4,7 @@ In mysh, variables are kept that control the behavior of the shell. This simple
4
4
  command is used to set, delete, and display these variables. The basic method
5
5
  for setting a variable is:
6
6
 
7
- set $name=value
7
+ set \$name=value
8
8
 
9
9
  Where:
10
10
  * name is a word matching the regex: /[a-z][a-z0-9_]*/. Lower case only.
@@ -14,7 +14,7 @@ To erase the value of a variable, use: set $$name=
14
14
  To display the name/value of a variable, use: set $$name
15
15
  To display all variable names/values use: set
16
16
 
17
- As an escapement, the string $$$$ maps to a single $$.
17
+ As an escapement, the strings $$$$ or \\$ map to a single $$.
18
18
 
19
19
  Some variables that are used in mysh are:
20
20
 
@@ -23,8 +23,8 @@ $$date_fmt The format for the date: "%Y-%m-%d". ie: 2017-01-09
23
23
  $$debug Does the shell display additional debugging info (true/false)
24
24
  $$h The home folder's path
25
25
  $$name The name given to this mysh session.
26
- $$post_prompt The prompt used when a line is continued with a trailing \\
27
- character.
26
+ $$post_prompt The prompt used when a line is continued with a trailing \
27
+ character. By default this just a single \
28
28
  $$pre_prompt A prompt string displayed before the actual command prompt.
29
29
  Delete the pre_prompt variable to disable pre-prompting.
30
30
  $$prompt The user prompt.