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
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ # 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
@@ -1,24 +1,24 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/internal/actions/vars.rb -- The mysh internal variables commands.
3
+ # The mysh internal variables commands.
4
4
  module Mysh
5
5
 
6
- #* mysh/internal/actions/vars.rb -- The mysh internal variable commands.
6
+ # The mysh internal variable commands.
7
7
  class VarsCommand < Action
8
8
 
9
- #The mysh variable parsing regex.
9
+ # The mysh variable parsing regex.
10
10
  VAR_EXP = %r{(?<name> [a-z][a-z0-9_]*){0}
11
11
  (?<equals> =){0}
12
12
  (?<value> \S.*){0}
13
13
  \$ (\g<name> \s* (\g<equals> \s* \g<value>?)?)?}x
14
14
 
15
- #Setup an internal action.
15
+ # Setup an internal action.
16
16
  def initialize(name, description)
17
17
  @var_name = @equals = @value = nil
18
18
  super(name, description)
19
19
  end
20
20
 
21
- #Execute a command against the internal mysh variables.
21
+ # Execute a command against the internal mysh variables.
22
22
  def process_command(input)
23
23
  if (match = VAR_EXP.match(input.raw_body))
24
24
  @var_name, @equals, @value = match[:name], match[:equals], match[:value]
@@ -30,7 +30,7 @@ module Mysh
30
30
  :internal
31
31
  end
32
32
 
33
- #Do the actual work here.
33
+ # Do the actual work here.
34
34
  def do_command
35
35
  sym = @var_name.to_sym if @var_name
36
36
 
@@ -45,7 +45,7 @@ module Mysh
45
45
  end
46
46
  end
47
47
 
48
- #Display all variables neatly.
48
+ # Display all variables neatly.
49
49
  def show_all_values
50
50
  puts (MNV.keys - ['$'.to_sym])
51
51
  .sort
@@ -55,7 +55,7 @@ module Mysh
55
55
 
56
56
  end
57
57
 
58
- #The show command action object.
58
+ # The set command action object.
59
59
  desc = 'Set/query mysh variables. See ?set for more.'
60
60
  COMMANDS.add_action(VarsCommand.new('set <$name>=value', desc))
61
61
  end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/init.rb -- The mysh init file loader.
3
+ # The mysh initial file loader.
4
4
  module Mysh
5
5
 
6
- #Set the init file used to startup mysh to none so far.
6
+ # Set the initial file used to startup mysh to none so far.
7
7
  $mysh_init_file = nil
8
8
 
9
- #Perform init phase processing.
9
+ # Perform initial phase processing.
10
10
  def self.mysh_load_init
11
11
 
12
12
  unless $mysh_init_file
@@ -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"
@@ -19,7 +19,10 @@ module Mysh
19
19
  MNV[:page_width] = "{{ MiniTerm.width }}"
20
20
  MNV[:page_height] = "{{ MiniTerm.height }}"
21
21
  MNV[:page_pause] = "on"
22
- MNV[:page_msg] = "Press a key, a space, or q:"
22
+
23
+ MNV[:history] = "on"
24
+ MNV[:no_dups] = "on"
25
+ MNV[:no_move] = "on"
23
26
 
24
27
  MNV[:d] = "{{ Time.now.strftime(MNV[:date_fmt]) }}"
25
28
  MNV[:h] = "{{ ENV['HOME'].to_host_spec }}"
@@ -31,4 +34,6 @@ module Mysh
31
34
 
32
35
  MNV[:date_fmt] = "%Y-%m-%d"
33
36
  MNV[:time_fmt] = "%H:%M"
37
+
38
+ MNV[:type] = "raw"
34
39
  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
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/shell_variables/shell_variable_keeper.rb -- The keeper of mysh values.
3
+ # The keeper of mysh values.
4
4
  module Mysh
5
5
 
6
- #The keeper of mysh variable values.
6
+ # The keeper of mysh variable values.
7
7
  class Keeper
8
8
 
9
- #Set up this variable
9
+ # Set up this variable
10
10
  def initialize(value="")
11
11
  @value = value
12
12
  end
13
13
 
14
- #Get the value of this variable.
14
+ # Get the value of this variable.
15
15
  def get_value(loop_check={})
16
16
  my_id = self.object_id
17
17
  fail "Mysh variable looping error." if loop_check[my_id]
@@ -21,12 +21,12 @@ module Mysh
21
21
  loop_check.delete(my_id)
22
22
  end
23
23
 
24
- #Get the source code of this variable.
24
+ # Get the source code of this variable.
25
25
  def get_source
26
26
  @value
27
27
  end
28
28
 
29
- #Set the value of this variable.
29
+ # Set the value of this variable.
30
30
  def set_value(value)
31
31
  @value = value
32
32
  end
@@ -34,4 +34,3 @@ module Mysh
34
34
  end
35
35
 
36
36
  end
37
-
@@ -1,19 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/shell_variables/shell_variable_store.rb -- Storage for mysh variables.
3
+ # Storage for mysh variables.
4
4
  module Mysh
5
5
 
6
- #The holder of mysh variables.
6
+ # The holder of mysh variables.
7
7
  module MNV
8
- #Set up the storage hash.
8
+ # Set up the storage hash.
9
9
  @store = Hash.new { |_hash, _key| Keeper.new }
10
10
 
11
- #The shared loop checker for programmatic access.
11
+ # The shared loop checker for programmatic access.
12
12
  @loop_check = nil
13
13
 
14
- #Get the value of a variable.
15
- #<br>Endemic Code Smells
16
- #* :reek:TooManyStatements
14
+ # Get the value of a variable.
15
+ # Endemic Code Smells :reek:TooManyStatements
17
16
  def self.[](index)
18
17
  keeper = get_keeper(index)
19
18
 
@@ -28,7 +27,7 @@ module Mysh
28
27
  end
29
28
  end
30
29
 
31
- #Set the value of a variable.
30
+ # Set the value of a variable.
32
31
  def self.[]=(index, value)
33
32
  unless value.empty?
34
33
  keeper = get_keeper(index)
@@ -41,32 +40,32 @@ module Mysh
41
40
  value
42
41
  end
43
42
 
44
- #Get the value keeper of a variable.
43
+ # Get the value keeper of a variable.
45
44
  def self.get_keeper(index)
46
45
  @store[index]
47
46
  end
48
47
 
49
- #Set the value keeper of a variable.
48
+ # Set the value keeper of a variable.
50
49
  def self.set_keeper(index, keeper)
51
50
  @store[index] = keeper
52
51
  end
53
52
 
54
- #Delete the value keeper of a variable.
53
+ # Delete the value keeper of a variable.
55
54
  def self.delete_keeper(index)
56
55
  @store.delete(index)
57
56
  end
58
57
 
59
- #Get the source code of a variable.
58
+ # Get the source code of a variable.
60
59
  def self.get_source(index)
61
60
  @store[index].get_source
62
61
  end
63
62
 
64
- #Does this entry exist?
63
+ # Does this entry exist?
65
64
  def self.key?(index)
66
65
  @store.key?(index)
67
66
  end
68
67
 
69
- #Get all the keys
68
+ # Get all the keys
70
69
  def self.keys
71
70
  @store.keys
72
71
  end
@@ -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}
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/sources/console.rb -- The mysh console command source.
3
+ # The mysh console command source.
4
4
  module Mysh
5
5
 
6
- #A wrapper for the mysh console terminal.
6
+ # A wrapper for the mysh console terminal.
7
7
  class Console
8
8
 
9
- #Setup the console wrapper.
9
+ # Setup the console wrapper.
10
10
  def initialize
11
11
  @eoi = false
12
12
  end
13
13
 
14
- #Get the initial line of command input.
14
+ # Get the initial line of command input.
15
15
  def get_command
16
16
  puts MNV[:pre_prompt] if MNV.key?(:pre_prompt)
17
17
  get(prompt: MNV[:prompt])
@@ -20,7 +20,7 @@ module Mysh
20
20
  exit
21
21
  end
22
22
 
23
- #Get additional lines of continued commands.
23
+ # Get additional lines of continued commands.
24
24
  def get_command_extra(str)
25
25
  get(prompt: MNV[:post_prompt] + '\\', prefix: str[0])
26
26
  rescue MiniReadlinePLE => err
@@ -38,15 +38,19 @@ module Mysh
38
38
  MNV[selector] = ""
39
39
  end
40
40
 
41
- #Have we reached the end of input?
41
+ # Have we reached the end of input?
42
42
  def eoi?
43
43
  @eoi
44
44
  end
45
45
 
46
46
  private
47
47
 
48
- #Get some actual user input!
48
+ # Get some actual user input!
49
49
  def get(parms={})
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)
53
+
50
54
  result = (input = Mysh.input).readline(parms)
51
55
  input.instance_options[:initial] = ""
52
56
  result
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/sources/parse.rb -- mysh general parser.
3
+ # mysh general parser.
4
4
  module Mysh
5
5
 
6
- #Parse a string into components.
7
- #<br>Endemic Code Smells
8
- #* :reek:TooManyStatements
6
+ # Parse a string into components.
7
+ # Endemic Code Smells :reek:TooManyStatements
9
8
  def self.parse_args(input)
10
9
  result, read_point = [], input.chars.each
11
10
 
@@ -24,9 +23,8 @@ module Mysh
24
23
 
25
24
  private
26
25
 
27
- #Get a string parameter.
28
- #<br>Endemic Code Smells
29
- #* :reek:TooManyStatements
26
+ # Get a string parameter.
27
+ # Endemic Code Smells :reek:TooManyStatements
30
28
  def self.get_string(read_point)
31
29
  result = ""
32
30
 
@@ -41,9 +39,8 @@ module Mysh
41
39
  [result]
42
40
  end
43
41
 
44
- #Get a parameter.
45
- #<br>Endemic Code Smells
46
- #* :reek:TooManyStatements
42
+ # Get a parameter.
43
+ # Endemic Code Smells :reek:TooManyStatements
47
44
  def self.get_parameter(first_char, read_point)
48
45
  result = first_char
49
46