mysh 0.1.17 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mysh.rb +28 -25
  3. data/lib/mysh/expression.rb +1 -9
  4. data/lib/mysh/external_ruby.rb +1 -1
  5. data/lib/mysh/internal/action.rb +3 -11
  6. data/lib/mysh/internal/action_pool.rb +6 -20
  7. data/lib/mysh/internal/actions/actions_path.rb +2 -2
  8. data/lib/mysh/internal/actions/cd.rb +14 -23
  9. data/lib/mysh/internal/actions/exit.rb +10 -7
  10. data/lib/mysh/internal/actions/gls.rb +63 -8
  11. data/lib/mysh/internal/actions/help.rb +20 -33
  12. data/lib/mysh/internal/actions/help/help.txt +4 -4
  13. data/lib/mysh/internal/actions/help/help_env.txt +14 -0
  14. data/lib/mysh/internal/actions/help/help_expr.txt +3 -2
  15. data/lib/mysh/internal/actions/help/help_gls.txt +41 -0
  16. data/lib/mysh/internal/actions/help/help_help.txt +7 -4
  17. data/lib/mysh/internal/actions/help/help_math.txt +1 -1
  18. data/lib/mysh/internal/actions/help/help_ruby.txt +21 -0
  19. data/lib/mysh/internal/actions/help/help_show.txt +12 -0
  20. data/lib/mysh/internal/actions/help/history.txt +19 -0
  21. data/lib/mysh/internal/actions/help/quick.txt +25 -0
  22. data/lib/mysh/internal/actions/help/sub_help.rb +41 -0
  23. data/lib/mysh/internal/actions/history.rb +46 -10
  24. data/lib/mysh/internal/actions/pwd.rb +18 -0
  25. data/lib/mysh/internal/actions/show.rb +22 -13
  26. data/lib/mysh/internal/actions/show/env.rb +43 -0
  27. data/lib/mysh/internal/actions/show/ruby.rb +50 -0
  28. data/lib/mysh/internal/actions/type.rb +27 -0
  29. data/lib/mysh/internal/actions/vls.rb +12 -12
  30. data/lib/mysh/internal/decorate.rb +2 -2
  31. data/lib/mysh/internal/format.rb +2 -4
  32. data/lib/mysh/internal/format/array.rb +23 -13
  33. data/lib/mysh/internal/format/bullets.rb +2 -2
  34. data/lib/mysh/internal/format/columns.rb +6 -11
  35. data/lib/mysh/internal/format/nil.rb +13 -0
  36. data/lib/mysh/internal/format/string.rb +23 -9
  37. data/lib/mysh/internal/manage.rb +2 -2
  38. data/lib/mysh/quick.rb +32 -0
  39. data/lib/mysh/user_input.rb +11 -4
  40. data/lib/mysh/user_input/parse.rb +1 -1
  41. data/lib/mysh/user_input/smart_source.rb +1 -1
  42. data/lib/mysh/version.rb +1 -1
  43. data/mysh.gemspec +1 -1
  44. data/samples/show.txt +1 -1
  45. data/tests/my_shell_tests.rb +25 -18
  46. metadata +16 -3
@@ -1,4 +1,4 @@
1
- mysh version: {{ Mysh::VERSION }}
1
+ Help: mysh version: {{ Mysh::VERSION }}
2
2
 
3
3
  The mysh is a shell program inspired by the Ruby programming language in the
4
4
  same way the csh was inspired by the "C" programming language.
@@ -6,12 +6,12 @@ same way the csh was inspired by the "C" programming language.
6
6
  In mysh, commands fall into one of three broad categories. There are:
7
7
 
8
8
  1) "=" expressions: Any line beginning with an "=" will be evaluated as a Ruby
9
- language expression. For more see the '? =' or '? math' commands.
9
+ language expression. For more see the '?=' or '?math' commands.
10
10
 
11
11
  2) Internal mysh commands are processed within mysh itself. The following set
12
12
  of commands are supported:
13
13
 
14
- {{ Mysh::COMMANDS.actions_info.mysh_bulletize.join("\n") }}
14
+ {{ Mysh::COMMANDS.actions_info.mysh_bulletize }}
15
15
 
16
16
  3) All other commands are executed by the system using the standard shell or
17
17
  the appropriate ruby interpreter. If the command has a '.rb' extension, it
@@ -23,5 +23,5 @@ In mysh, commands fall into one of three broad categories. There are:
23
23
  Note: If an internal command has the same name as an external command, adding a
24
24
  leading space will force the use of the external command.
25
25
 
26
- Help on help: For a list of all help topics see the '? ?' command.
26
+ Help on help: For a list of all help topics see the '??' command.
27
27
 
@@ -0,0 +1,14 @@
1
+ Help: mysh show env command summary:
2
+
3
+ The show env (or @env) command is used to display useful information about the
4
+ current execution environment. This includes:
5
+
6
+ user - The current user name.
7
+ home - The current home directory.
8
+ name - The path/name of the mysh program currently executing.
9
+ shell - The path/name of the system command shell.
10
+ host - The name of the host computer.
11
+ os - The current operating system.
12
+
13
+ path - An easy-to-read, formatted version of the current search path.
14
+
@@ -1,6 +1,7 @@
1
- mysh Ruby expression support summary:
1
+ Help: mysh Ruby expression support summary:
2
2
 
3
- All command lines that begin with = are evaluated as Ruby expressions.
3
+ All command lines that begin with = are evaluated as Ruby expressions. The
4
+ results of this evaluation are displayed.
4
5
 
5
6
  Notes:
6
7
 
@@ -0,0 +1,41 @@
1
+ Help: mysh gls command summary:
2
+
3
+ The gls command is used to display information about the loaded ruby gems. The
4
+ usage template for this command is:
5
+
6
+ mysh>gls <options> <mask>
7
+
8
+ Where:
9
+
10
+ <options> is one of:
11
+ "-l" -- display detailed information on the selected gems.
12
+ none -- display only the names of the selected gems.
13
+
14
+ <mask> is an optional, case-sensitive pattern for filtering out the gems
15
+ displayed. If omitted, all gems are displayed.
16
+
17
+ Examples:
18
+
19
+ mysh>gls
20
+ actionpack erubis mini_readline rails-deprecated_sanitizer tzinfo
21
+ actionview i18n minitest rails-dom-testing vls
22
+ activesupport in_array nokogiri rails-html-sanitizer
23
+ bigdecimal json psych railties
24
+ builder loofah rack thor
25
+ crass mini_portile2 rack-test thread_safe
26
+
27
+ mysh>gls -l vls
28
+ name vls
29
+ version 0.4.0
30
+ date 2016-10-08 00:00:00 UTC
31
+ summary A version listing utility.
32
+ description A CLI and Rails console utility that lists the versions of modules
33
+ used by the specified gems/ruby files or Rails project.
34
+ executables vls
35
+ authors Peter Camilleri
36
+ email peter.c.camilleri@gmail.com
37
+ homepage http://teuthida-technologies.com/
38
+
39
+ A complete guide to the gem specification's properties may be found at:
40
+ http://guides.rubygems.org/specification-reference/
41
+
@@ -1,9 +1,12 @@
1
- mysh Help command summary:
1
+ Help: mysh help command summary:
2
2
 
3
- The help (or ?) command is used to get either general help about mysh
4
- or an optional specified topic.
3
+ The help (or ?) command is used to get either general help about mysh or an
4
+ optional specified topic.
5
+
6
+ If the longer form, help is used, a space is required before the topic. If the
7
+ quick form, ? is used, the space is optional.
5
8
 
6
9
  The available help topics are:
7
10
 
8
- {{ HELP.actions_info.mysh_bulletize.join("\n") }}
11
+ {{ HELP.actions_info.mysh_bulletize }}
9
12
 
@@ -1,4 +1,4 @@
1
- mysh Math support summary:
1
+ Help: mysh math support summary:
2
2
 
3
3
  The Ruby expression execution environment has direct access to many advanced
4
4
  mathematical functions and values.
@@ -0,0 +1,21 @@
1
+ Help: mysh show ruby command summary:
2
+
3
+ The show ruby (or @ruby) command is used to display useful information about
4
+ the current ruby environment. This includes:
5
+
6
+ location - The path/name of the current ruby interpreter.
7
+ description - A comprehensive summary of the version and other such data.
8
+ version - The version of ruby.
9
+ patch - Its patch level.
10
+ revision - Its revision level.
11
+ date - The date of its release.
12
+ platform - The target platform.
13
+ copyright - The legal ownership of the software.
14
+ engine - The internal engine in the software.
15
+ host - A summary of the host operating environment.
16
+ host cpu - A (crude) approximation of the installed cpu.
17
+ host os - The current operating system.
18
+ host vendor - The current environment vendor/genre.
19
+
20
+ $: - An easy-to-read, formatted version of $: or the ruby search path.
21
+
@@ -0,0 +1,12 @@
1
+ Help: mysh show command summary:
2
+
3
+ The show (or @) command is used to inspect various aspects of the mysh
4
+ environment specified by the item parameter.
5
+
6
+ If the longer form, show is used, a space is required before the topic. If the
7
+ quick form, @ is used, the space is optional.
8
+
9
+ The available show items are:
10
+
11
+ {{ SHOW.actions_info.mysh_bulletize }}
12
+
@@ -0,0 +1,19 @@
1
+ Help: mysh history command summary:
2
+
3
+ The history (or !) command is used to allow the user greater control over the
4
+ history of commands that have been entered. The action taken by the history
5
+ command is controlled by an optional parameter.
6
+
7
+ If the longer form, show is used, a space is required before the parameter. If
8
+ the quick form, ! is used, the space is optional.
9
+
10
+ Quick Long Command
11
+ Form Form Description
12
+ ===== ======= ===========
13
+ ! history Display the history buffer.
14
+
15
+ !5 history 5 Retrieve history entry 5 and present this to the user
16
+ as the next command.
17
+
18
+ !clear history clear Clear the command history.
19
+
@@ -0,0 +1,25 @@
1
+ Help: mysh quick commands summary:
2
+
3
+ In mysh, some commands are identified by a single character, making them easy
4
+ and quick to enter. Since these commands are always a single character long,
5
+ it is not necessary (but still acceptable) to place a space between the command
6
+ and any parameter.
7
+
8
+ To be processed as quick, the character must be first in the line.
9
+
10
+ The supported quick commands are:
11
+
12
+ Quick Long Command
13
+ Form Form Description
14
+ ===== ======= ===========
15
+ ! history Display the mysh command history, or if an index is specified,
16
+ retrieve the command with that index value.
17
+
18
+ = All command lines that begin with = are evaluated as Ruby
19
+ expressions. The results of this evaluation are displayed.
20
+
21
+ ? help Display help information for mysh with an optional topic.
22
+
23
+ @ show The show (or @) command is used to inspect various aspects of
24
+ the mysh environment specified by the item parameter.
25
+
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+
3
+ #* mysh/internal/actions/help/sub_help.rb -- The mysh internal help sub commands.
4
+ module Mysh
5
+
6
+ #* mysh/internal/actions/help/sub_help.rb -- The mysh internal help sub commands.
7
+ class HelpSubCommand < Action
8
+
9
+ #Setup a help command.
10
+ def initialize(name, description, file_name)
11
+ super(name, description)
12
+ @file_name = file_name
13
+ end
14
+
15
+ #Execute a help command.
16
+ def call(_args)
17
+ show_handlebar_file(ACTIONS_PATH + 'help/' + @file_name)
18
+ end
19
+
20
+ end
21
+
22
+ help = [['', 'General help on mysh.', 'help.txt' ],
23
+ ['show', 'Help on the show command.', 'help_show.txt'],
24
+ ['@', 'Help on the show command.', 'help_show.txt'],
25
+ ['env', 'Help on the show env command.', 'help_env.txt' ],
26
+ ['ruby', 'Help on the show ruby command.', 'help_ruby.txt'],
27
+ ['math', 'Help on math functions.', 'help_math.txt'],
28
+ ['=', 'Help on ruby expressions.', 'help_expr.txt'],
29
+ ['quick', 'Help on quick commands.', 'quick.txt' ],
30
+ ['gls', 'Help on gls internal mysh command.', 'help_gls.txt' ],
31
+ ['!', 'This help on the history command.', 'history.txt' ],
32
+ ['history', 'This help on the history command.', 'history.txt' ],
33
+ ['help', 'This help on the help command.', 'help_help.txt'],
34
+ ['?', 'This help on the help command.', 'help_help.txt']
35
+ ]
36
+
37
+ help.each do |parms|
38
+ HELP.add_action(HelpSubCommand.new(*parms))
39
+ end
40
+
41
+ end
@@ -1,21 +1,57 @@
1
1
  # coding: utf-8
2
2
 
3
- #* internal/actions/history.rb -- The mysh internal history command.
3
+ #* mysh/internal/actions/history.rb -- The mysh internal history command.
4
4
  module Mysh
5
5
 
6
- #* history.rb -- The mysh internal history command.
7
- class Action
8
- #Add the exit command to the library.
9
- COMMANDS.add('history', 'Display the mysh command history.') do |args|
10
- history = Mysh.input.history
6
+ #* mysh/internal/actions/history.rb -- The mysh internal history command.
7
+ class HistoryCommand < Action
8
+
9
+ #Execute the history command.
10
+ def call(args)
11
+ @args, @history = args, Mysh.input.history
11
12
 
12
13
  #The history command should not be part of the history.
13
- history.pop
14
+ @history.pop
15
+
16
+ pull_index || clear_history || show_history
17
+ end
14
18
 
15
- puts history
19
+ private
20
+
21
+ #Deal with history index arguments
22
+ def pull_index
23
+ index = @args[0].to_i
24
+
25
+ if (1..@history.length) === index
26
+ Mysh.input.instance_options[:initial] = @history[index-1]
27
+ else
28
+ false
29
+ end
30
+ end
31
+
32
+ #Clear the history buffer.
33
+ def clear_history
34
+ if @args[0] == 'clear'
35
+ @history.clear
36
+ else
37
+ false
38
+ end
39
+ end
40
+
41
+ #Just show the history.
42
+ def show_history
43
+ @history.each_with_index do |item, index|
44
+ puts "#{index+1}: #{item}"
45
+ end
16
46
  end
17
47
 
18
- COMMANDS.add_alias('!', 'history')
19
48
  end
20
- end
21
49
 
50
+ #Add the history commands to the library.
51
+ desc = 'Display the mysh command history, or if an index is specified, ' +
52
+ 'retrieve the command with that index value.'
53
+ COMMANDS.add_action(HistoryCommand.new('history <index>', desc))
54
+ #The history command action object.
55
+ HISTORY_COMMAND = HistoryCommand.new('!<index>', desc)
56
+ COMMANDS.add_action(HISTORY_COMMAND)
57
+ end
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+
3
+ #* mysh/internal/actions/pwd.rb -- The mysh internal pwd command.
4
+ module Mysh
5
+
6
+ #* mysh/internal/actions/pwd.rb -- The mysh internal pwd command.
7
+ class PwdCommand < Action
8
+
9
+ #Execute the cd command.
10
+ def call(_args)
11
+ puts decorate(Dir.pwd)
12
+ end
13
+
14
+ end
15
+
16
+ desc = 'Display the current working directory.'
17
+ COMMANDS.add_action(PwdCommand.new('pwd', desc))
18
+ end
@@ -1,27 +1,36 @@
1
1
  # coding: utf-8
2
2
 
3
- #* internal/actions/show.rb -- The mysh show command.
3
+ #* mysh/internal/actions/show.rb -- The mysh internal show command.
4
4
  module Mysh
5
5
 
6
- #* internal/actions/show.rb -- The mysh show command.
7
- class Action
8
-
9
- # The base help command.
10
- desc = 'Display a text file with optional embedded handlebars.'
11
-
12
- COMMANDS.add('show <file>', desc) do |args|
13
- file_name = args.shift
6
+ #Show items.
7
+ SHOW = ActionPool.new("SHOW") do |args|
8
+ puts "No show data found for #{args[0].inspect}. See ?@ for more."
9
+ end
14
10
 
15
- @exec_binding = binding
11
+ #* mysh/internal/actions/show.rb -- The mysh internal show command.
12
+ class ShowCommand < Action
16
13
 
17
- if file_name
18
- show_handlebar_file(file_name)
14
+ #Execute a help command by routing it to a sub-command.
15
+ #<br>Endemic Code Smells
16
+ #* :reek:UtilityFunction
17
+ def call(args)
18
+ if args.empty?
19
+ puts "An item is needed for the show command."
19
20
  else
20
- puts "Error: A text file must be specified."
21
+ SHOW[args[0]].call(args)
21
22
  end
22
23
  end
23
24
 
24
25
  end
25
26
 
27
+ # The base help command.
28
+ desc = 'Display information about a part of mysh. See ?@ for more.'
29
+ COMMANDS.add_action(ShowCommand.new('show <item>', desc))
30
+ #The show command action object.
31
+ SHOW_COMMAND = ShowCommand.new('@<item>', desc)
32
+ COMMANDS.add_action(SHOW_COMMAND)
26
33
  end
27
34
 
35
+ #Load up the extra help actions!
36
+ Dir[Mysh::Action::ACTIONS_PATH + 'show/*.rb'].each {|file| require file }
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ #* mysh/internal/actions/show/env.rb -- Get help on the mysh environment.
4
+ module Mysh
5
+
6
+ #* mysh/internal/actions/show/env.rb -- Get help on the mysh environment.
7
+ class EnvInfoCommand < Action
8
+
9
+ #Execute the ? shell command.
10
+ def call(_args)
11
+ puts "Key mysh environment information.", ""
12
+ puts info.mysh_bulletize, "",
13
+ path.mysh_bulletize, ""
14
+ end
15
+
16
+ private
17
+
18
+ #Get the info
19
+ def info
20
+ [["user", ENV['USER']],
21
+ ["home", ENV['HOME']],
22
+ ["name", decorate($PROGRAM_NAME)],
23
+ ["shell", ENV['SHELL'] || ENV['ComSpec']],
24
+ ["host", ENV['HOSTNAME'] || ENV['COMPUTERNAME']],
25
+ ["os", ENV['OS']],
26
+ ["term", ENV['TERM']],
27
+ ["disp", ENV['DISPLAY']],
28
+ ["edit", ENV['EDITOR']]]
29
+ end
30
+
31
+ #Get the path.
32
+ #<br>Endemic Code Smells
33
+ #* :reek:UtilityFunction
34
+ def path
35
+ [["path"].concat(ENV['PATH'].split(File::PATH_SEPARATOR))]
36
+ end
37
+
38
+ end
39
+
40
+ desc = 'Get information about the current shell environment. ' +
41
+ 'See ?env for more.'
42
+ SHOW.add_action(EnvInfoCommand.new('env', desc))
43
+ end
@@ -0,0 +1,50 @@
1
+ # coding: utf-8
2
+
3
+ #* mysh/internal/actions/show/ruby.rb -- Get help on the ruby environment.
4
+ module Mysh
5
+
6
+ #* mysh/internal/actions/show/ruby.rb -- Get help on the ruby environment.
7
+ class RubyInfoCommand < Action
8
+
9
+ #Execute the ? shell command.
10
+ def call(_args)
11
+ puts "Key ruby environment information.", ""
12
+ puts info.mysh_bulletize, "",
13
+ path.mysh_bulletize, ""
14
+ end
15
+
16
+ private
17
+
18
+ #Get the info
19
+ #<br>Endemic Code Smells
20
+ #* :reek:UtilityFunction
21
+ def info
22
+ [["location", RbConfig.ruby],
23
+ ["description", RUBY_DESCRIPTION],
24
+ ["version", RUBY_VERSION],
25
+ ["patch", RUBY_PATCHLEVEL],
26
+ ["revision", RUBY_REVISION],
27
+ ["date", RUBY_RELEASE_DATE],
28
+ ["platform", RUBY_PLATFORM],
29
+ ["copyright", RUBY_COPYRIGHT],
30
+ ["engine", RUBY_ENGINE],
31
+ ["host", RbConfig::CONFIG['host']],
32
+ ["host cpu", RbConfig::CONFIG['host_cpu']],
33
+ ["host os", RbConfig::CONFIG['host_os']],
34
+ ["host vendor", RbConfig::CONFIG['host_vendor']]
35
+ ]
36
+ end
37
+
38
+ #Get the path.
39
+ #<br>Endemic Code Smells
40
+ #* :reek:UtilityFunction
41
+ def path
42
+ [["$:"].concat($:)]
43
+ end
44
+
45
+ end
46
+
47
+ desc = 'Get information about the current ruby environment. ' +
48
+ 'See ?ruby for more.'
49
+ SHOW.add_action(RubyInfoCommand.new('ruby', desc))
50
+ end