mysh 0.6.9 → 0.6.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -5
  3. data/lib/mysh.rb +19 -9
  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/expression.rb +11 -31
  18. data/lib/mysh/external.rb +4 -5
  19. data/lib/mysh/globalize.rb +14 -10
  20. data/lib/mysh/handlebars.rb +10 -13
  21. data/lib/mysh/handlebars/eval_handlebars.rb +38 -0
  22. data/lib/mysh/{internal/actions/help → help}/env.txt +0 -0
  23. data/lib/mysh/{internal/actions/help → help}/expr.txt +0 -0
  24. data/lib/mysh/{internal/actions/help → help}/gem.txt +0 -0
  25. data/lib/mysh/{internal/actions/help → help}/gls.txt +0 -0
  26. data/lib/mysh/{internal/actions/help → help}/h_o_h.txt +1 -1
  27. data/lib/mysh/{internal/actions/help → help}/hbar.txt +11 -0
  28. data/lib/mysh/{internal/actions/help → help}/help.txt +0 -0
  29. data/lib/mysh/{internal/actions/help → help}/history.txt +7 -0
  30. data/lib/mysh/{internal/actions/help → help}/init.txt +0 -0
  31. data/lib/mysh/{internal/actions/help → help}/kbd.txt +0 -0
  32. data/lib/mysh/{internal/actions/help → help}/math.txt +0 -0
  33. data/lib/mysh/{internal/actions/help → help}/mls.txt +0 -0
  34. data/lib/mysh/{internal/actions/help → help}/quick.txt +0 -0
  35. data/lib/mysh/{internal/actions/help → help}/ruby.txt +0 -0
  36. data/lib/mysh/{internal/actions/help → help}/show.txt +0 -0
  37. data/lib/mysh/{internal/actions/help → help}/term.txt +0 -0
  38. data/lib/mysh/{internal/actions/help → help}/timed.txt +0 -0
  39. data/lib/mysh/help/type.txt +28 -0
  40. data/lib/mysh/{internal/actions/help → help}/types.txt +0 -0
  41. data/lib/mysh/{internal/actions/help → help}/usage.txt +0 -0
  42. data/lib/mysh/{internal/actions/help → help}/vars.txt +4 -4
  43. data/lib/mysh/input_wrapper.rb +13 -13
  44. data/lib/mysh/internal.rb +20 -8
  45. data/lib/mysh/internal/{actions/cancel.rb → cancel.rb} +0 -0
  46. data/lib/mysh/internal/{actions/cd.rb → cd.rb} +2 -2
  47. data/lib/mysh/internal/{actions/comment.rb → comment.rb} +2 -2
  48. data/lib/mysh/internal/{actions/elapsed.rb → elapsed.rb} +2 -2
  49. data/lib/mysh/internal/{actions/exit.rb → exit.rb} +0 -0
  50. data/lib/mysh/internal/{actions/gls.rb → gls.rb} +6 -7
  51. data/lib/mysh/internal/{actions/help.rb → help.rb} +7 -9
  52. data/lib/mysh/internal/{actions/history.rb → history.rb} +10 -9
  53. data/lib/mysh/internal/load.rb +45 -0
  54. data/lib/mysh/internal/{actions/mls.rb → mls.rb} +2 -2
  55. data/lib/mysh/internal/{actions/pwd.rb → pwd.rb} +1 -1
  56. data/lib/mysh/internal/{actions/say.rb → say.rb} +1 -1
  57. data/lib/mysh/internal/{actions/show.rb → show.rb} +7 -6
  58. data/lib/mysh/internal/{actions/help → support}/sub_help.rb +9 -7
  59. data/lib/mysh/internal/type.rb +38 -0
  60. data/lib/mysh/internal/{actions/vars.rb → vars.rb} +8 -8
  61. data/lib/mysh/{init.rb → load_init_file.rb} +3 -3
  62. data/lib/mysh/process.rb +7 -7
  63. data/lib/mysh/quick.rb +10 -4
  64. data/lib/mysh/shell_variables.rb +9 -4
  65. data/lib/mysh/shell_variables/evaluate.rb +2 -11
  66. data/lib/mysh/shell_variables/shell_variable_keeper.rb +6 -7
  67. data/lib/mysh/shell_variables/shell_variable_store.rb +13 -14
  68. data/lib/mysh/{internal/actions/show → show}/env.rb +3 -5
  69. data/lib/mysh/{internal/actions/show → show}/gem.rb +3 -16
  70. data/lib/mysh/{internal/actions/show → show}/ruby.rb +0 -0
  71. data/lib/mysh/{internal/actions/show → show}/term.rb +5 -7
  72. data/lib/mysh/sources/console.rb +11 -7
  73. data/lib/mysh/sources/parse.rb +7 -10
  74. data/lib/mysh/sources/smart_auto_complete.rb +5 -5
  75. data/lib/mysh/sources/string.rb +6 -6
  76. data/lib/mysh/string_helpers.rb +37 -0
  77. data/lib/mysh/system.rb +2 -2
  78. data/lib/mysh/user_input.rb +5 -9
  79. data/lib/mysh/version.rb +4 -4
  80. data/mysh.gemspec +4 -3
  81. data/samples/show.txt +2 -0
  82. data/tests/my_shell_tests.rb +18 -6
  83. metadata +77 -65
  84. data/lib/mysh/binding_wrapper.rb +0 -21
  85. data/lib/mysh/handlebars/string.rb +0 -22
  86. data/lib/mysh/internal/actions/actions_path.rb +0 -15
  87. data/lib/mysh/internal/actions/command_line/quit.rb +0 -19
  88. data/lib/mysh/internal/actions/load.rb +0 -36
  89. data/lib/mysh/internal/actions/type.rb +0 -22
  90. data/lib/mysh/internal/manage.rb +0 -20
  91. data/lib/mysh/internal/to_file_spec.rb +0 -26
  92. data/lib/mysh/pre_processor.rb +0 -11
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ # Monkey patches for Mysh handlebars
4
+ class String
5
+
6
+ # Evaluate any variable substitutions in the input.
7
+ def eval_handlebars(evaluator=$mysh_exec_binding)
8
+ string, text, buffer = self, "", []
9
+
10
+ # Translate the string with embedded code into Ruby code.
11
+ until string.empty?
12
+ text, code, string = string.partition(/{{.*?}}/m)
13
+
14
+ unless text.empty?
15
+ text = text.gsub(/\\[{}]/) {|found| found[1]}
16
+ buffer << "_m_<<#{text.inspect};"
17
+ else
18
+ buffer << "" if buffer.empty?
19
+ end
20
+
21
+ unless code.empty?
22
+ if code[-3] == "#"
23
+ buffer << "#{code[2...-3]};"
24
+ else
25
+ buffer << "_m_<<(#{code[2...-2]}).to_s;"
26
+ end
27
+ end
28
+ end
29
+
30
+ # Evaluate the result of the translation.
31
+ if buffer.length > 1
32
+ evaluator.eval("_m_ = '';" + buffer.join + "_m_")
33
+ else
34
+ text
35
+ end
36
+ end
37
+
38
+ end
@@ -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
 
@@ -30,6 +30,17 @@ those cases, simply end the expression with a '#' character. For example:
30
30
  mysh>echo \{\{ "not embedded" #\}\} \{\{ "embedded" \}\}
31
31
  embedded
32
32
 
33
+ A common use for not embedded code snippets is to act as the control
34
+ structures. For example:
35
+
36
+ \{\{ 3.times do |i| #\}\} The count is: \{\{ i+1 \}\}
37
+ \{\{ end #\}\}
38
+
39
+ Yields the following output:
40
+
41
+ {{ 3.times do |i| #}} The count is: {{ i+1 }}
42
+ {{ end #}}
43
+
33
44
  Finally, it may be that it is desired to embed braces into a text file or
34
45
  the command line. In that case precede the brace with a backslash character
35
46
  like: \\{ or \\}
@@ -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.
@@ -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 }
@@ -1,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/cd.rb -- The mysh internal cd command.
3
+ # The mysh internal cd command.
4
4
  module Mysh
5
5
 
6
- #Add the cd command to the library.
6
+ # Add the cd command to the library.
7
7
  desc = 'Change directory to the optional <dir> parameter ' +
8
8
  'or display the current working directory.'
9
9
 
@@ -1,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/comment.rb -- A mysh internal comment.
3
+ # A mysh internal comment.
4
4
  module Mysh
5
5
 
6
- #Add comments to the library.
6
+ # Add comments to the library.
7
7
  desc = 'A mysh comment. No action taken'
8
8
  action = lambda {|_input| :internal}
9
9
 
@@ -1,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/elapsed.rb -- The mysh internal elapsed command.
3
+ # The mysh internal elapsed command.
4
4
  module Mysh
5
5
 
6
- #Add the elapsed commands to the library.
6
+ # Add the elapsed commands to the library.
7
7
  desc = 'Execute a command and then display the elapsed time. See ?% for more.'
8
8
 
9
9
  action = lambda do |input|
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/gls.rb -- The mysh gls (gem ls) command.
3
+ # The mysh gls (gem ls) command.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/gls.rb -- The mysh gls (gem ls) command.
6
+ # The mysh gls (gem ls) command.
7
7
  class GlsCommand < Action
8
8
 
9
- #Set up this command.
9
+ # Set up this command.
10
10
  def initialize(*args)
11
11
  super
12
12
  @report = @mask = @specs = nil
13
13
  end
14
14
 
15
- #Execute the gls command.
15
+ # Execute the gls command.
16
16
  def process_command(input)
17
17
  process_args(input.args)
18
18
  gather_gems
@@ -57,9 +57,8 @@ module Mysh
57
57
  report.puts_format_output_bullets
58
58
  end
59
59
 
60
- #Get detailed information on a gem specification.
61
- #<br>Endemic Code Smells
62
- #* :reek:UtilityFunction
60
+ # Get detailed information on a gem specification.
61
+ # Endemic Code Smells :reek:UtilityFunction
63
62
  def info(spec)
64
63
  [["name", spec.name],
65
64
  ["version", spec.version],
@@ -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'
@@ -1,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/history.rb -- The mysh internal history command.
3
+ # The mysh internal history command.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/history.rb -- The mysh internal history command.
6
+ # The mysh internal history command.
7
7
  class HistoryCommand < Action
8
8
 
9
9
  #Set up this command.
@@ -12,11 +12,11 @@ module Mysh
12
12
  @args = @history = nil
13
13
  end
14
14
 
15
- #Execute the history command.
15
+ # Execute the history command.
16
16
  def process_command(input)
17
17
  @args, @history = input.args, Mysh.input.history
18
18
 
19
- #The history command should not be part of the history.
19
+ # The history command should not be part of the history.
20
20
  @history.pop
21
21
 
22
22
  pull_index || clear_history || show_history
@@ -24,7 +24,7 @@ module Mysh
24
24
 
25
25
  private
26
26
 
27
- #Deal with history index arguments
27
+ # Deal with history index arguments
28
28
  def pull_index
29
29
  index = @args[0].to_i
30
30
 
@@ -35,7 +35,7 @@ module Mysh
35
35
  end
36
36
  end
37
37
 
38
- #Clear the history buffer.
38
+ # Clear the history buffer.
39
39
  def clear_history
40
40
  if @args[0] == 'clear'
41
41
  @history.clear
@@ -44,7 +44,7 @@ module Mysh
44
44
  end
45
45
  end
46
46
 
47
- #Just show the history.
47
+ # Just show the history.
48
48
  def show_history
49
49
  pattern = Regexp.new(@args[0] || /./)
50
50
 
@@ -55,10 +55,11 @@ module Mysh
55
55
 
56
56
  end
57
57
 
58
- #Add the history commands to the library.
58
+ # Add the history commands to the library.
59
59
  desc = 'Display the mysh command history. See ?! for more.'
60
60
  COMMANDS.add_action(HistoryCommand.new('history <arg>', desc))
61
- #The history command action object.
61
+
62
+ # The history command action object.
62
63
  HISTORY_COMMAND = HistoryCommand.new('!<arg>', desc)
63
64
  COMMANDS.add_action(HISTORY_COMMAND)
64
65
  end