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
@@ -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
@@ -8,14 +8,12 @@ module Mysh
8
8
 
9
9
  # Execute the @env shell command.
10
10
  def process_command(_args)
11
- print WORKING unless @ran_once
11
+ print WORKING
12
12
  Gem.refresh
13
13
 
14
14
  puts "Key mysh environment information.", "",
15
15
  info.format_output_bullets, "",
16
16
  path.format_output_bullets, ""
17
-
18
- @ran_once = true
19
17
  end
20
18
 
21
19
  private
@@ -23,12 +21,12 @@ module Mysh
23
21
  # Get the info
24
22
  # Endemic Code Smells :reek:UtilityFunction
25
23
  def info
26
- [["about", Mysh::SUMMARY],
24
+ [["about", Mysh::DESCRIPTION],
27
25
  ["version", Mysh::VERSION],
28
26
  ["installed", Gem::Specification.find_all_by_name("mysh")
29
27
  .map{|s| s.version.to_s}
30
28
  .join(", ")],
31
- ["latest", insouciant {Gem.latest_version_for("mysh").to_s}],
29
+ ["latest", insouciant {latest_version_for("mysh").to_s}],
32
30
  ["init file", $mysh_init_file.to_host_spec],
33
31
  ["user", ENV['USER']],
34
32
  ["home", (ENV['HOME'] || "").to_host_spec],
@@ -8,7 +8,7 @@ module Mysh
8
8
 
9
9
  #Execute the @gem shell command.
10
10
  def process_command(input)
11
- print WORKING unless @ran_once
11
+ print WORKING
12
12
  Gem.refresh
13
13
 
14
14
  args = input.cooked_body.split(" ")[1..-1]
@@ -19,7 +19,6 @@ module Mysh
19
19
  specific(args)
20
20
  end
21
21
 
22
- @ran_once = true
23
22
  end
24
23
 
25
24
  private
@@ -61,7 +60,7 @@ module Mysh
61
60
 
62
61
  # Get gem info on the specified gems
63
62
  def specific(args)
64
- details = []
63
+ fetcher, details = Gem::SpecFetcher.new, []
65
64
 
66
65
  args.each do |gem_name|
67
66
  version_list = Gem::Specification.find_all_by_name(gem_name)
@@ -69,7 +68,7 @@ module Mysh
69
68
  .join(", ")
70
69
  details << [gem_name, version_list]
71
70
 
72
- latest = insouciant {latest_version_for(gem_name).to_s}
71
+ latest = insouciant {latest_version_for(gem_name, fetcher).to_s}
73
72
  details << ["latest", latest]
74
73
  details << [" ", " "]
75
74
  end
@@ -78,18 +77,6 @@ module Mysh
78
77
  details.format_output_bullets
79
78
  end
80
79
 
81
- # Get the latest version for the named gem. Patched code.
82
- def latest_version_for(name)
83
- dependency = Gem::Dependency.new(name)
84
- fetcher = Gem::SpecFetcher.fetcher
85
- if specs = fetcher.spec_for_dependency(dependency)[0][-1]
86
- spec = specs[0]
87
- spec && spec.version
88
- else
89
- "<Not found in repository>"
90
- end
91
- end
92
-
93
80
  end
94
81
 
95
82
  desc = 'Get information about the current gem support or ' +
@@ -8,13 +8,11 @@ module Mysh
8
8
 
9
9
  #Execute the @term shell command.
10
10
  def process_command(_args)
11
- print WORKING unless @ran_once
11
+ print WORKING
12
12
  Gem.refresh
13
13
 
14
14
  puts "Key term information.", "",
15
15
  info.format_output_bullets, ""
16
-
17
- @ran_once = true
18
16
  end
19
17
 
20
18
  private
@@ -22,18 +20,20 @@ module Mysh
22
20
  # Get the info
23
21
  # Endemic Code Smells :reek:UtilityFunction
24
22
  def info
23
+ fetcher = Gem::SpecFetcher.new
24
+
25
25
  [["about", MiniReadline::DESCRIPTION],
26
26
  ["version", MiniReadline::VERSION],
27
27
  ["installed", Gem::Specification.find_all_by_name("mini_readline")
28
28
  .map{|s| s.version.to_s}
29
29
  .join(", ")],
30
- ["latest", insouciant {Gem.latest_version_for("mini_readline").to_s}],
30
+ ["latest", insouciant {latest_version_for("mini_readline", fetcher).to_s}],
31
31
  ["about", MiniTerm::DESCRIPTION],
32
32
  ["version", MiniTerm::VERSION],
33
33
  ["installed", Gem::Specification.find_all_by_name("mini_term")
34
34
  .map{|s| s.version.to_s}
35
35
  .join(", ")],
36
- ["latest", insouciant {Gem.latest_version_for("mini_term").to_s}],
36
+ ["latest", insouciant {latest_version_for("mini_term", fetcher).to_s}],
37
37
  ["platform", MiniTerm::TERM_PLATFORM.inspect],
38
38
  ["term type", MiniTerm::TERM_TYPE.inspect],
39
39
  ["columns", MiniTerm.width.to_s],
@@ -45,8 +45,6 @@ module Mysh
45
45
  ]
46
46
  end
47
47
 
48
-
49
-
50
48
  end
51
49
 
52
50
  desc = 'Get information about the console. See ?term for more.'
@@ -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
 
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/sources/smart_auto_complete.rb - An adaptive source for auto-complete.
3
+ # An adaptive source for auto-complete.
4
4
  module Mysh
5
5
 
6
- #* array_source.rb - An array as the source for auto-complete.
6
+ # An array as the source for auto-complete.
7
7
  class SmartSource
8
8
 
9
- #Create a new file/folder auto-data source. NOP
9
+ # Create a new file/folder auto-data source. NOP
10
10
  def initialize(options)
11
11
  @prefix = options[:prefix]
12
12
  @auto_source = MiniReadline::AutoFileSource.new(options)
@@ -14,7 +14,7 @@ module Mysh
14
14
  @active_source = nil
15
15
  end
16
16
 
17
- #Construct a new data list for auto-complete
17
+ # Construct a new data list for auto-complete
18
18
  def rebuild(str)
19
19
  if /(?<=\s|^)\$[a-z][a-z0-9_]*\z/ =~ str
20
20
  sym = $MATCH[1..-1].to_sym
@@ -26,7 +26,7 @@ module Mysh
26
26
  @active_source.rebuild(str)
27
27
  end
28
28
 
29
- #Get the next string for auto-complete
29
+ # Get the next string for auto-complete
30
30
  def next
31
31
  @active_source ? @active_source.next : @str
32
32
  end
@@ -1,18 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/sources/string.rb -- The mysh string command source.
3
+ # The mysh string command source.
4
4
  module Mysh
5
5
 
6
- #A wrapper for a string with mysh commands.
6
+ # A wrapper for a string with mysh commands.
7
7
  class StringSource
8
8
 
9
- #Setup the string source.
9
+ # Setup the string source.
10
10
  def initialize(str)
11
11
  @eoi = false
12
12
  @read_pt = str.lines.each
13
13
  end
14
14
 
15
- #Get the initial line of command input.
15
+ # Get the initial line of command input.
16
16
  def get_command(_str="")
17
17
  @read_pt.next
18
18
  rescue StopIteration
@@ -20,10 +20,10 @@ module Mysh
20
20
  "\n"
21
21
  end
22
22
 
23
- #Set up an alias as these two are identical.
23
+ # Set up an alias as these two are identical.
24
24
  alias :get_command_extra :get_command
25
25
 
26
- #Have we reached the end of input?
26
+ # Have we reached the end of input?
27
27
  def eoi?
28
28
  @eoi
29
29
  end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ # Monkey patches for Mysh string data.
4
+ class String
5
+
6
+ # Extract Boolean data from this string.
7
+ def extract_boolean
8
+ self !~ /\A(false|no|off)?\z/i
9
+ end
10
+
11
+ # Make the file name fit the local system.
12
+ def to_host_spec
13
+ self.dress_up_slashes
14
+ .dress_up_quotes
15
+ end
16
+
17
+ # Dress up slashes and backslashes.
18
+ def dress_up_slashes
19
+ MiniTerm.windows? ? self.gsub("/", "\\") : self
20
+ end
21
+
22
+ # Dress up in quotes if needed.
23
+ def dress_up_quotes
24
+ self[' '] ? "\"#{self}\"" : self
25
+ end
26
+
27
+ # Make the file name fit the standard notation.
28
+ def to_std_spec
29
+ self.gsub("\\", "/")
30
+ end
31
+
32
+ # The mysh string pre-processor stack.
33
+ def preprocess(evaluator=$mysh_exec_binding)
34
+ self.eval_variables.eval_handlebars(evaluator)
35
+ end
36
+
37
+ end
@@ -1,9 +1,9 @@
1
1
  # coding: utf-8
2
2
 
3
- #* mysh/system.rb -- Support for executing through the system.
3
+ # Support for executing through the system.
4
4
  module Mysh
5
5
 
6
- #Try to execute as a system program.
6
+ # Try to execute as a system program.
7
7
  def self.try_execute_system(input)
8
8
  system(input.raw.preprocess.chomp + "\n") ? :system : :error
9
9
  end
@@ -1,22 +1,20 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'mini_readline'
4
-
5
3
  require_relative 'sources/console'
6
4
  require_relative 'sources/string'
7
5
 
8
6
  require_relative 'sources/smart_auto_complete'
9
7
  require_relative 'sources/parse'
10
8
 
11
- #* mysh/user_input.rb -- Get some text from the user.
9
+ # Get some text from the user.
12
10
  module Mysh
13
11
 
14
- #Get one command from the user.
12
+ # Get one command from the user.
15
13
  def self.get_command(source)
16
14
  get_command_extra(source, source.get_command)
17
15
  end
18
16
 
19
- #Get any continuations of the inputs
17
+ # Get any continuations of the inputs
20
18
  def self.get_command_extra(source, str)
21
19
  if str.start_with?("=") && /\\\s*$/ =~ str
22
20
  get_command_extra(source, $PREMATCH + "\n" + source.get_command_extra(str))
@@ -25,13 +23,11 @@ module Mysh
25
23
  end
26
24
  end
27
25
 
28
- #Get the user input ready.
26
+ # Get the user input ready.
29
27
  def self.input
30
- @input ||= MiniReadline::Readline.new(history: true,
31
- eoi_detect: true,
28
+ @input ||= MiniReadline::Readline.new(eoi_detect: true,
32
29
  auto_complete: true,
33
30
  auto_source: SmartSource)
34
31
  end
35
32
 
36
33
  end
37
-