mysh 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +162 -51
- data/lib/mysh.rb +4 -2
- data/lib/mysh/{external_ruby.rb → external.rb} +6 -7
- data/lib/mysh/handlebars.rb +1 -1
- data/lib/mysh/init.rb +14 -9
- data/lib/mysh/input_wrapper.rb +67 -0
- data/lib/mysh/internal/action.rb +5 -16
- data/lib/mysh/internal/action_pool.rb +1 -1
- data/lib/mysh/internal/actions/cd.rb +8 -15
- data/lib/mysh/internal/actions/command_line.rb +3 -3
- data/lib/mysh/internal/actions/comment.rb +3 -11
- data/lib/mysh/internal/actions/elapsed.rb +9 -16
- data/lib/mysh/internal/actions/exit.rb +4 -11
- data/lib/mysh/internal/actions/gls.rb +2 -2
- data/lib/mysh/internal/actions/help.rb +6 -3
- data/lib/mysh/internal/actions/help/sub_help.rb +2 -2
- data/lib/mysh/internal/actions/history.rb +2 -2
- data/lib/mysh/internal/actions/load.rb +24 -30
- data/lib/mysh/internal/actions/pwd.rb +3 -11
- data/lib/mysh/internal/actions/quit.rb +3 -11
- data/lib/mysh/internal/actions/say.rb +3 -12
- data/lib/mysh/internal/actions/show.rb +16 -19
- data/lib/mysh/internal/actions/show/env.rb +5 -5
- data/lib/mysh/internal/actions/show/ruby.rb +1 -1
- data/lib/mysh/internal/actions/type.rb +11 -17
- data/lib/mysh/internal/actions/vars.rb +2 -2
- data/lib/mysh/internal/actions/vls.rb +11 -16
- data/lib/mysh/internal/manage.rb +5 -19
- data/lib/mysh/process.rb +8 -12
- data/lib/mysh/quick.rb +11 -11
- data/lib/mysh/system.rb +11 -0
- data/lib/mysh/version.rb +1 -1
- data/tests/my_shell_tests.rb +25 -7
- metadata +5 -3
data/lib/mysh/internal/action.rb
CHANGED
@@ -12,14 +12,15 @@ module Mysh
|
|
12
12
|
attr_reader :description
|
13
13
|
|
14
14
|
#Setup an internal action.
|
15
|
-
def initialize(name, description)
|
15
|
+
def initialize(name = "", description = "", &action)
|
16
16
|
@name, @description = name, description.in_array
|
17
|
-
|
17
|
+
|
18
|
+
define_singleton_method(:process_command, &action) if block_given?
|
18
19
|
end
|
19
20
|
|
20
21
|
#Parse the string and call the action.
|
21
|
-
def
|
22
|
-
|
22
|
+
def process_quick_command(input)
|
23
|
+
process_command(input.quick)
|
23
24
|
:internal
|
24
25
|
end
|
25
26
|
|
@@ -28,23 +29,11 @@ module Mysh
|
|
28
29
|
[@name].concat(@description)
|
29
30
|
end
|
30
31
|
|
31
|
-
#Evaluate the string in the my shell context.
|
32
|
-
def mysh_eval(str)
|
33
|
-
@exec_binding.eval(str)
|
34
|
-
end
|
35
|
-
|
36
32
|
#Get the name without any argument descriptions.
|
37
33
|
def short_name
|
38
34
|
name.split[0] || ""
|
39
35
|
end
|
40
36
|
|
41
|
-
private
|
42
|
-
|
43
|
-
#Create a binding for mysh to execute expressions in.
|
44
|
-
def mysh_binding
|
45
|
-
binding
|
46
|
-
end
|
47
|
-
|
48
37
|
end
|
49
38
|
|
50
39
|
end
|
@@ -3,22 +3,15 @@
|
|
3
3
|
#* mysh/internal/actions/cd.rb -- The mysh internal cd command.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
#* mysh/internal/actions/cd.rb -- The mysh internal cd command.
|
7
|
-
class CdCommand < Action
|
8
|
-
|
9
|
-
#Execute the cd command.
|
10
|
-
def call(args)
|
11
|
-
Dir.chdir(args[0]) unless args.empty?
|
12
|
-
puts Dir.pwd.decorate
|
13
|
-
rescue => err
|
14
|
-
puts "Error: #{err}"
|
15
|
-
puts err.backtrace if MNV[:debug]
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
6
|
#Add the cd command to the library.
|
21
7
|
desc = 'Change directory to the optional <dir> parameter ' +
|
22
8
|
'and then display the current working directory.'
|
23
|
-
|
9
|
+
|
10
|
+
action = lambda do |input|
|
11
|
+
args = input.args
|
12
|
+
Dir.chdir(args[0]) unless args.empty?
|
13
|
+
puts Dir.pwd.decorate
|
14
|
+
end
|
15
|
+
|
16
|
+
COMMANDS.add_action(Action.new('cd <dir>', desc, &action))
|
24
17
|
end
|
@@ -15,12 +15,12 @@ module Mysh
|
|
15
15
|
#Execute a post-boot command line option.
|
16
16
|
def post_boot(_args); end
|
17
17
|
|
18
|
-
alias :
|
18
|
+
alias :process_command :pre_boot
|
19
19
|
|
20
20
|
#Get an argument for an option.
|
21
21
|
def get_arg(read_point)
|
22
22
|
result = read_point.next
|
23
|
-
fail if COMMAND_LINE.exists?(result)
|
23
|
+
fail if COMMAND_LINE.exists?(result) #An arg should not be a command!
|
24
24
|
result
|
25
25
|
rescue
|
26
26
|
fail "Error in #{short_name.inspect}: Invalid argument: #{result.inspect}"
|
@@ -46,7 +46,7 @@ module Mysh
|
|
46
46
|
puts "", msg, ""
|
47
47
|
end
|
48
48
|
|
49
|
-
HELP["usage"].
|
49
|
+
HELP["usage"].process_command(nil)
|
50
50
|
exit
|
51
51
|
end
|
52
52
|
|
@@ -3,18 +3,10 @@
|
|
3
3
|
#* mysh/internal/actions/comment.rb -- A mysh internal comment.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
#* mysh/internal/actions/comment.rb -- A mysh internal comment.
|
7
|
-
class MyshComment < Action
|
8
|
-
|
9
|
-
#Ignore a comment.
|
10
|
-
def call(_args)
|
11
|
-
:internal
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
6
|
#Add comments to the library.
|
17
7
|
desc = 'A mysh comment. No action taken'
|
18
|
-
|
8
|
+
action = lambda {|_input| :internal}
|
9
|
+
|
10
|
+
MYSH_COMMENT = Action.new('#<stuff>', desc, &action)
|
19
11
|
COMMANDS.add_action(MYSH_COMMENT)
|
20
12
|
end
|
@@ -3,25 +3,18 @@
|
|
3
3
|
#* mysh/internal/actions/elapsed.rb -- The mysh internal elapsed command.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#Execute the elapsed command.
|
10
|
-
#<br>Endemic Code Smells
|
11
|
-
#* :reek:DuplicateMethodCall -- needed due to time side effects.
|
12
|
-
def call(str)
|
13
|
-
start_time = Time.now
|
14
|
-
Mysh.try_execute_command(str[1..-1])
|
15
|
-
end_time = Time.now
|
6
|
+
#Add the elapsed commands to the library.
|
7
|
+
desc = 'Execute a command and then display the elapsed time.'
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
action = lambda do |input|
|
10
|
+
start_time = Time.now
|
11
|
+
Mysh.try_execute_command(input.quick_body)
|
12
|
+
end_time = Time.now
|
20
13
|
|
14
|
+
puts "Elapsed execution time = #{"%.3f" % (end_time - start_time)} seconds."
|
15
|
+
:internal
|
21
16
|
end
|
22
17
|
|
23
|
-
|
24
|
-
desc = 'Execute a command and then display the elapsed time.'
|
25
|
-
TIMED_COMMAND = TimedCommand.new('%<command>', desc)
|
18
|
+
TIMED_COMMAND = Action.new('%<command>', desc, &action)
|
26
19
|
COMMANDS.add_action(TIMED_COMMAND)
|
27
20
|
end
|
@@ -3,16 +3,9 @@
|
|
3
3
|
#* mysh/internal/actions/exit.rb -- The mysh internal exit command.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
#* mysh/internal/actions/exit.rb -- The mysh internal exit command.
|
7
|
-
class ExitCommand < Action
|
8
|
-
|
9
|
-
#Execute the exit command.
|
10
|
-
def call(_args)
|
11
|
-
raise MyshExit
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
6
|
#Add the exit command to the library.
|
17
|
-
|
7
|
+
desc = 'Exit the current mysh level.'
|
8
|
+
action = lambda {|_input| raise MyshExit}
|
9
|
+
|
10
|
+
COMMANDS.add_action(Action.new('exit', desc, &action))
|
18
11
|
end
|
@@ -4,18 +4,21 @@
|
|
4
4
|
module Mysh
|
5
5
|
|
6
6
|
# Help action pool of topics.
|
7
|
-
|
7
|
+
default = Action.new do |args|
|
8
8
|
puts "No help found for #{args[0].inspect}."
|
9
9
|
end
|
10
10
|
|
11
|
+
HELP = ActionPool.new("HELP", default)
|
12
|
+
|
11
13
|
#* mysh/internal/actions/help.rb -- The mysh internal help command.
|
12
14
|
class HelpCommand < Action
|
13
15
|
|
14
16
|
#Execute a help command by routing it to a sub-command.
|
15
17
|
#<br>Endemic Code Smells
|
16
18
|
#* :reek:UtilityFunction
|
17
|
-
def
|
18
|
-
|
19
|
+
def process_command(input)
|
20
|
+
args = input.args
|
21
|
+
HELP[args[0] || ""].process_command(args)
|
19
22
|
end
|
20
23
|
|
21
24
|
end
|
@@ -13,8 +13,8 @@ module Mysh
|
|
13
13
|
end
|
14
14
|
|
15
15
|
#Execute the history command.
|
16
|
-
def
|
17
|
-
@args, @history = args, Mysh.input.history
|
16
|
+
def process_command(input)
|
17
|
+
@args, @history = input.args, Mysh.input.history
|
18
18
|
|
19
19
|
#The history command should not be part of the history.
|
20
20
|
@history.pop
|
@@ -3,40 +3,34 @@
|
|
3
3
|
#* mysh/internal/actions/load.rb -- The mysh load command.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
:internal
|
27
|
-
else
|
28
|
-
fail "Error: Unknown file type: #{file_name.inspect}"
|
29
|
-
end
|
30
|
-
|
6
|
+
#Add the load command to the library.
|
7
|
+
desc = "Load a ruby program, mysh script, " +
|
8
|
+
"or text file into the mysh environment."
|
9
|
+
|
10
|
+
action = lambda do |input|
|
11
|
+
args = input.args
|
12
|
+
file_name = args.shift
|
13
|
+
|
14
|
+
if file_name
|
15
|
+
file_ext = File.extname(file_name)
|
16
|
+
|
17
|
+
if file_ext == '.mysh'
|
18
|
+
Mysh.process_file(file_name)
|
19
|
+
:internal
|
20
|
+
elsif file_ext == '.txt'
|
21
|
+
show_handlebar_file(file_name, BindingWrapper.new(binding))
|
22
|
+
:internal
|
23
|
+
elsif file_ext == '.rb'
|
24
|
+
load file_name
|
25
|
+
:internal
|
31
26
|
else
|
32
|
-
fail "Error:
|
27
|
+
fail "Error: Unknown file type: #{file_name.inspect}"
|
33
28
|
end
|
34
29
|
|
30
|
+
else
|
31
|
+
fail "Error: A load file must be specified."
|
35
32
|
end
|
36
|
-
|
37
33
|
end
|
38
34
|
|
39
|
-
|
40
|
-
desc = 'Load a ruby program, mysh script, or text file into the mysh environment.'
|
41
|
-
COMMANDS.add_action(LoadCommand.new('load file', desc))
|
35
|
+
COMMANDS.add_action(Action.new('load file', desc, &action))
|
42
36
|
end
|
@@ -3,16 +3,8 @@
|
|
3
3
|
#* mysh/internal/actions/pwd.rb -- The mysh internal pwd command.
|
4
4
|
module Mysh
|
5
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 Dir.pwd.decorate
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
6
|
desc = 'Display the current working directory.'
|
17
|
-
|
7
|
+
action = lambda {|_input| puts Dir.pwd.decorate}
|
8
|
+
|
9
|
+
COMMANDS.add_action(Action.new('pwd', desc, &action))
|
18
10
|
end
|
@@ -3,16 +3,8 @@
|
|
3
3
|
#* mysh/internal/actions/quit.rb -- The mysh internal quit command.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
#* mysh/internal/actions/quit.rb -- The mysh internal quit command.
|
7
|
-
class QuitCommand < Action
|
8
|
-
|
9
|
-
#Execute the quit command.
|
10
|
-
def call(_args)
|
11
|
-
exit
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
6
|
#Add the quit command to the library.
|
17
|
-
|
7
|
+
desc = 'Quit out of the mysh.'
|
8
|
+
|
9
|
+
COMMANDS.add_action(Action.new('quit', desc) {|_input| exit })
|
18
10
|
end
|
@@ -3,18 +3,9 @@
|
|
3
3
|
#* mysh/internal/actions/say.rb -- A mysh internal say command.
|
4
4
|
module Mysh
|
5
5
|
|
6
|
-
#* mysh/internal/actions/say.rb -- A mysh internal say command.
|
7
|
-
class SayCommand < Action
|
8
|
-
|
9
|
-
#Say something!
|
10
|
-
def call(args)
|
11
|
-
puts args.join(' ')
|
12
|
-
:internal
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
6
|
#Add says to the library.
|
18
7
|
desc = 'Display the text in the command arguments.'
|
19
|
-
|
8
|
+
action = lambda {|input| puts input.cooked_body}
|
9
|
+
|
10
|
+
COMMANDS.add_action(Action.new('say <stuff>', desc, &action))
|
20
11
|
end
|
@@ -4,31 +4,28 @@
|
|
4
4
|
module Mysh
|
5
5
|
|
6
6
|
#Show items.
|
7
|
-
|
8
|
-
puts "No show data found for #{
|
7
|
+
default = Action.new do |input|
|
8
|
+
puts "No show data found for #{input.raw.inspect}. See ?@ for more."
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#<br>Endemic Code Smells
|
16
|
-
#* :reek:UtilityFunction :reek:FeatureEnvy
|
17
|
-
def call(args)
|
18
|
-
if args.empty?
|
19
|
-
puts "An item is needed for the show command."
|
20
|
-
else
|
21
|
-
SHOW[args[0]].call(args)
|
22
|
-
end
|
23
|
-
end
|
11
|
+
SHOW = ActionPool.new("SHOW", default)
|
12
|
+
|
13
|
+
#The shared description.
|
14
|
+
desc = "Display information about a part of mysh. See ?@ for more."
|
24
15
|
|
16
|
+
action = lambda do |input|
|
17
|
+
item = input.args[0]
|
18
|
+
|
19
|
+
if item.empty?
|
20
|
+
puts "An item is needed for the show command."
|
21
|
+
else
|
22
|
+
SHOW[item].process_command(input)
|
23
|
+
end
|
25
24
|
end
|
26
25
|
|
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
26
|
#The show command action object.
|
31
|
-
|
27
|
+
COMMANDS.add_action(Action.new('show <item>', desc, &action))
|
28
|
+
SHOW_COMMAND = Action.new('@<item>', desc, &action)
|
32
29
|
COMMANDS.add_action(SHOW_COMMAND)
|
33
30
|
end
|
34
31
|
|
@@ -7,7 +7,7 @@ module Mysh
|
|
7
7
|
class EnvInfoCommand < Action
|
8
8
|
|
9
9
|
#Execute the ? shell command.
|
10
|
-
def
|
10
|
+
def process_command(_args)
|
11
11
|
puts "Key mysh environment information.", ""
|
12
12
|
puts info.format_mysh_bullets, "",
|
13
13
|
path.format_mysh_bullets, ""
|
@@ -20,15 +20,15 @@ module Mysh
|
|
20
20
|
#* :reek:UtilityFunction
|
21
21
|
def info
|
22
22
|
[["version", Mysh::VERSION],
|
23
|
-
["init file", $mysh_init_file],
|
23
|
+
["init file", $mysh_init_file.decorate],
|
24
24
|
["user", ENV['USER']],
|
25
|
-
["home", ENV['HOME']],
|
25
|
+
["home", (ENV['HOME'] || "").decorate],
|
26
26
|
["name", $PROGRAM_NAME.decorate],
|
27
|
-
["os shell", ENV['SHELL']
|
27
|
+
["os shell", (ENV['SHELL'] || ENV['ComSpec'] || "").decorate],
|
28
28
|
["host", ENV['HOSTNAME'] || ENV['COMPUTERNAME']],
|
29
29
|
["os", ENV['OS']],
|
30
30
|
["platform", MiniReadline::TERM_PLATFORM],
|
31
|
-
["java?", MiniReadline::TERM_JAVA
|
31
|
+
["java?", MiniReadline::TERM_JAVA ? true : false],
|
32
32
|
["term", ENV['TERM']],
|
33
33
|
["disp", ENV['DISPLAY']],
|
34
34
|
["edit", ENV['EDITOR']]]
|