mysh 0.6.12 → 0.6.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -3
  3. data/lib/mysh.rb +11 -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 +9 -11
  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 +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 +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 +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} +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 -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 +3 -2
  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 +4 -7
  78. data/lib/mysh/version.rb +4 -4
  79. data/mysh.gemspec +4 -4
  80. data/tests/my_shell_tests.rb +12 -3
  81. metadata +79 -81
  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
@@ -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
 
@@ -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.
@@ -1,62 +1,62 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/input_wrapper.rb -- An action compatible wrapper for a input.
3
+ # An action compatible wrapper for a input.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/input_wrapper.rb -- An action compatible wrapper for a input.
6
+ # An action compatible wrapper for a input.
7
7
  class InputWrapper
8
8
 
9
- #Build an input wrapper.
9
+ # Build an input wrapper.
10
10
  def initialize(raw)
11
11
  @raw = raw.chomp
12
12
  @raw_command = @raw_body = nil
13
13
  end
14
14
 
15
- #Access the raw text.
15
+ # Access the raw text.
16
16
  attr_reader :raw
17
17
 
18
- #Get the first raw character.
18
+ # Get the first raw character.
19
19
  def quick_command
20
20
  @raw[0] || ""
21
21
  end
22
22
 
23
- #Get the balance of the raw string.
23
+ # Get the balance of the raw string.
24
24
  def quick_body
25
25
  @raw[1..-1] || ""
26
26
  end
27
27
 
28
- #Get the command word if it exists.
28
+ # Get the command word if it exists.
29
29
  def raw_command
30
30
  @raw_command ||= @raw.split[0] || ""
31
31
  end
32
32
 
33
- #Get the parameter text.
33
+ # Get the parameter text.
34
34
  def raw_body
35
35
  @raw_body ||= @raw[(raw_command.length + 1)..-1] || ""
36
36
  end
37
37
 
38
- #Get the preprocessed argument text.
38
+ # Get the preprocessed argument text.
39
39
  def cooked_body
40
40
  raw_body.preprocess
41
41
  end
42
42
 
43
- #Access the massaged text.
43
+ # Access the massaged text.
44
44
  def cooked
45
45
  body = cooked_body
46
46
  raw_command + (body.empty? ? "" : " " + body)
47
47
  end
48
48
 
49
- #Get the parsed arguments
49
+ # Get the parsed arguments
50
50
  def args
51
51
  Mysh.parse_args(cooked_body)
52
52
  end
53
53
 
54
- #Get the parsed command line.
54
+ # Get the parsed command line.
55
55
  def parsed
56
56
  [raw_command] + args
57
57
  end
58
58
 
59
- #Set up input for a quick style command.
59
+ # Set up input for a quick style command.
60
60
  def quick
61
61
  @raw_command = quick_command
62
62
  @raw_body = quick_body
@@ -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 }