mysh 0.6.12 → 0.6.13

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1181f7c07f14be213795e5af840e9364e838ada9
4
- data.tar.gz: 0005e8503ddd7a6905d834c85e01519f920ca65f
3
+ metadata.gz: da3781a854769fe73c280fd78399ddb6d26cdd64
4
+ data.tar.gz: 8e70d3df6a194b26e639deefdff63f9cc871fe1a
5
5
  SHA512:
6
- metadata.gz: 536851ba0c923a4e2491d5abd50c417f8f3c6992cc61c885920d1c4654219c95efd40fbfcaf3a1574e94687a602248914b40a13a4a938f55993911d9903b3006
7
- data.tar.gz: 5ccbc4d1709a355aa9d3a8b065aacee3dbe9c6620bcfb26f70fd27b8fedd89cffdeb03d88314dd747a7d0b3d64977c7f6f303673791e26127ce81569b511f852
6
+ metadata.gz: '099048a82d4c3f4e4f1f6951ec5d3bc90ad8229f22158308b2bcf1fc6a90d0f365c42a31c5fe9fa1f9c32ad609fb9c12d3a9a8d3d594128f10fbb7615902addd'
7
+ data.tar.gz: bdda1b66bfa676b915be21f8a6c4b1cf20212ec8ad0e4209ac1119a2e02a5b39c6539dc2f1b8c90342a707d24be5303fc34dbea17d31e8cde7567bea8012c321
data/README.md CHANGED
@@ -423,6 +423,7 @@ $debug | Does the shell display additional debugging info (true/false)
423
423
  $h | The home folder's path
424
424
  $history | Is command line history enabled?
425
425
  $name | The name given to this mysh session.
426
+ $no_dups | Suppress duplicate entries in the history buffer.
426
427
  $no_move | Entries are not moved up when pulled from the command history.
427
428
  $page_height| The page height.
428
429
  $page_msg | The paging message. Default is "Press a key, a space, or q:"
@@ -435,6 +436,7 @@ $r | The location of the Ruby compiler.
435
436
  $s | The location of the host command interpreter.
436
437
  $t | The current time.
437
438
  $time_fmt | The format for the time: "%H:%M"
439
+ $type | Does the type command operate in cooked or raw mode. Default is raw mode.
438
440
  $u | The current user.
439
441
  $w | The current working directory's path.
440
442
 
@@ -558,18 +560,19 @@ none | General help on mysh.
558
560
  @ | Help on the show command.
559
561
  env | Help on the show env command.
560
562
  gem | Help on the show gem command.
561
- gls | Help on gls internal mysh command.
563
+ gls | Help on the gls command.
562
564
  help | This help on the help command.
563
565
  history | Help on the history command.
564
566
  init | Help on mysh initialization.
565
567
  kbd | Help on mysh keyboard mapping.
566
568
  math | Help on math functions.
567
- mls | Help on mls internal mysh command.
569
+ mls | Help on the mls command.
568
570
  quick | Help on quick commands.
569
571
  ruby | Help on the show ruby command.
570
572
  set | Help on mysh variables.
571
573
  show | Help on the show command.
572
574
  term | Help on the show term command.
575
+ type | Help on the type command.
573
576
  types | Help on mysh file types.
574
577
  usage | Help on mysh usage options.
575
578
  {{ | Help on mysh handlebars.
@@ -714,7 +717,7 @@ pwd | Display the current working directory.
714
717
  say <stuff> | Display the text in the command arguments.
715
718
  set <$name>=value| Set/query mysh variables.
716
719
  show <item> | Display information about a part of mysh.
717
- type <file> | Display a text file with support for optional embedded handlebars and mysh variables.
720
+ type <file> | Display one or more text files with optional support for embedded handlebars and shell variables.
718
721
 
719
722
  Notes:
720
723
  1. The notation {x} means that x is optional.
@@ -7,24 +7,31 @@ require 'English'
7
7
  require 'in_array'
8
8
  require 'pause_output'
9
9
  require 'format_output'
10
+ require 'mini_readline'
11
+
12
+ # The path to the gem lib folder.
13
+ MYSH_LIB = (File.expand_path(File.dirname(__FILE__)) + "/").freeze
10
14
 
11
15
  require_relative 'mysh/exceptions'
16
+ require_relative 'mysh/string_helpers'
12
17
  require_relative 'mysh/input_wrapper'
13
18
  require_relative 'mysh/user_input'
19
+ require_relative 'mysh/action'
20
+ require_relative 'mysh/action_pool'
14
21
  require_relative 'mysh/internal'
15
22
  require_relative 'mysh/quick'
16
23
  require_relative 'mysh/external'
24
+ require_relative 'mysh/command_line'
17
25
  require_relative 'mysh/system'
18
26
  require_relative 'mysh/handlebars'
19
27
  require_relative 'mysh/shell_variables'
20
- require_relative 'mysh/pre_processor'
21
28
  require_relative 'mysh/process'
22
29
  require_relative 'mysh/globalize'
23
- require_relative 'mysh/init'
30
+ require_relative 'mysh/load_init_file'
24
31
  require_relative 'mysh/expression'
25
32
  require_relative 'mysh/version'
26
33
 
27
- # The Mysh (MY SHell) module. A container for mysh and its functionality.
34
+ # The Mysh (MY SHell) module.
28
35
  module Mysh
29
36
 
30
37
  # The actual shell method.
@@ -1,35 +1,35 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/action.rb -- The framework of mysh internal actions.
3
+ # The framework of mysh internal actions.
4
4
  module Mysh
5
5
 
6
- #The mysh internal action class.
6
+ # The mysh internal action class.
7
7
  class Action
8
- #The name of the action.
8
+ # The name of the action.
9
9
  attr_reader :name
10
10
 
11
- #The description of the action.
11
+ # The description of the action.
12
12
  attr_reader :description
13
13
 
14
- #Setup an internal action.
14
+ # Setup an internal action.
15
15
  def initialize(name = "", description = "", &action)
16
16
  @name, @description = name, description.in_array
17
17
 
18
18
  define_singleton_method(:process_command, &action) if block_given?
19
19
  end
20
20
 
21
- #Parse the string and call the action.
21
+ # Parse the string and call the action.
22
22
  def process_quick_command(input)
23
23
  process_command(input.quick)
24
24
  :internal
25
25
  end
26
26
 
27
- #Get information about the action.
27
+ # Get information about the action.
28
28
  def action_info
29
29
  [@name].concat(@description)
30
30
  end
31
31
 
32
- #Get the name without any argument descriptions.
32
+ # Get the name without any argument descriptions.
33
33
  def short_name
34
34
  name.split[0] || ""
35
35
  end
@@ -1,31 +1,31 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/action_pool.rb -- A managed hash of mysh actions.
3
+ # A managed hash of mysh actions.
4
4
  module Mysh
5
5
 
6
- #* A managed hash of mysh actions.
6
+ # A managed hash of mysh actions.
7
7
  class ActionPool
8
8
 
9
- #The name of this action pool.
9
+ # The name of this action pool.
10
10
  attr_reader :pool_name
11
11
 
12
- #Create a new action pool
12
+ # Create a new action pool
13
13
  def initialize(pool_name, default_action = nil)
14
14
  @pool_name, @pool = pool_name, {}
15
15
  @pool.default = default_action
16
16
  end
17
17
 
18
- #Get a action.
18
+ # Get a action.
19
19
  def [](index)
20
20
  @pool[index]
21
21
  end
22
22
 
23
- #Does this action exist?
23
+ # Does this action exist?
24
24
  def exists?(index)
25
25
  @pool.key?(index)
26
26
  end
27
27
 
28
- #Add an action to the pool.
28
+ # Add an action to the pool.
29
29
  def add_action(action)
30
30
  short_name = action.short_name
31
31
 
@@ -36,7 +36,7 @@ module Mysh
36
36
  @pool[short_name] = action
37
37
  end
38
38
 
39
- #Get information on all actions.
39
+ # Get information on all actions.
40
40
  def actions_info
41
41
  @pool
42
42
  .values
@@ -1,23 +1,23 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/command_line.rb -- The mysh internal command line option.
3
+ # The command line options of mysh.
4
4
  module Mysh
5
5
 
6
6
  # Action pool of command line options.
7
7
  COMMAND_LINE = ActionPool.new("COMMAND_LINE")
8
8
 
9
- #* mysh/internal/actions/command_line.rb -- The mysh internal command line option.
9
+ # A mysh command line option.
10
10
  class CommandOption < Action
11
11
 
12
- #Execute a pre-boot command line option.
12
+ # Execute a pre-boot command line option.
13
13
  def pre_boot(_args); end
14
14
 
15
- #Execute a post-boot command line option.
15
+ # Execute a post-boot command line option.
16
16
  def post_boot(_args); end
17
17
 
18
18
  alias :process_command :pre_boot
19
19
 
20
- #Get an argument for an option.
20
+ # Get an argument for an option.
21
21
  def get_arg(read_point)
22
22
  result = read_point.next
23
23
  fail if COMMAND_LINE.exists?(result) #An arg should not be a command!
@@ -28,9 +28,8 @@ module Mysh
28
28
 
29
29
  end
30
30
 
31
- #Execute command line options.
32
- #<br>Endemic Code Smells
33
- #* :reek:TooManyStatements
31
+ # Execute command line options.
32
+ # Endemic Code Smells :reek:TooManyStatements
34
33
  def self.process_command_args(args, phase)
35
34
  read_point = args.each
36
35
 
@@ -56,5 +55,6 @@ module Mysh
56
55
 
57
56
  end
58
57
 
59
- #Load up the extra help actions!
60
- Dir[Mysh::Action::ACTIONS_PATH + 'command_line/*.rb'].each {|file| require file }
58
+ # Load up the extra help actions!
59
+ path = MYSH_LIB + "mysh/command_line/*.rb"
60
+ Dir[path].each {|file| require file }
@@ -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
@@ -33,8 +32,7 @@ class Object
33
32
  fetcher ||= Gem::SpecFetcher.new
34
33
 
35
34
  if specs = fetcher.spec_for_dependency(dependency)[0][-1]
36
- spec = specs[0]
37
- spec && spec.version
35
+ specs[0].version
38
36
  else
39
37
  "<Not found in repository>"
40
38
  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
+
@@ -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