mysh 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/mysh.rb +2 -1
- data/lib/mysh/commands/help.rb +10 -21
- data/lib/mysh/commands/help.txt +14 -0
- data/lib/mysh/commands/help_math.txt +6 -2
- data/lib/mysh/commands/help_ruby.txt +15 -0
- data/lib/mysh/expression.rb +6 -9
- data/lib/mysh/smart_source.rb +28 -0
- data/lib/mysh/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a1fe687d859a5bcd1b9d9c5752a37d0204373e
|
4
|
+
data.tar.gz: b141ac7759e49a617717f77c49fe60faeb92540b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c6a1c87904fd42c6cb2267c34d9233934d4180bce918ba427bc8e759f0dc724e196ce1b3d460f050aed7993619c62d8a70c57ff43a0893bf031ce259e025d7
|
7
|
+
data.tar.gz: e584dbab723de2722996b57c10e20883939c5c46799d4f8d724e1424378640005f83ab1779d9f9df345255cd2f58c003f63cd7e4984357e85b442e9e1e172c6c
|
data/lib/mysh.rb
CHANGED
@@ -9,6 +9,7 @@ require 'English'
|
|
9
9
|
$no_alias_read_line_module = true
|
10
10
|
require 'mini_readline'
|
11
11
|
|
12
|
+
require_relative 'mysh/smart_source'
|
12
13
|
require_relative 'mysh/internal'
|
13
14
|
require_relative 'mysh/expression'
|
14
15
|
require_relative 'mysh/version'
|
@@ -29,7 +30,7 @@ module Mysh
|
|
29
30
|
@input = MiniReadline::Readline.new(history: true,
|
30
31
|
eoi_detect: true,
|
31
32
|
auto_complete: true,
|
32
|
-
auto_source:
|
33
|
+
auto_source: SmartSource)
|
33
34
|
|
34
35
|
loop do
|
35
36
|
input = @input.readline(prompt: 'mysh> ')
|
data/lib/mysh/commands/help.rb
CHANGED
@@ -10,39 +10,28 @@ module Mysh
|
|
10
10
|
|
11
11
|
#Add the exit command to the library.
|
12
12
|
add(self.new('help', 'Display help information for mysh.') do |args|
|
13
|
-
puts "mysh (MY SHell) version: #{Mysh::VERSION}"
|
13
|
+
puts "mysh (MY ruby SHell) version: #{Mysh::VERSION}"
|
14
14
|
puts
|
15
15
|
|
16
16
|
if args.empty?
|
17
17
|
width = 0
|
18
|
-
puts "Internal mysh commands:"
|
18
|
+
puts "1) Internal mysh commands:"
|
19
19
|
puts " - executed by mysh directly."
|
20
|
-
puts " -
|
20
|
+
puts " - supports the following set of commands."
|
21
21
|
puts
|
22
|
+
puts "Command Description"
|
23
|
+
puts "======= ==========="
|
22
24
|
|
23
25
|
InternalCommand
|
24
26
|
.info
|
25
|
-
.
|
26
|
-
.
|
27
|
-
width = [width, first[0].length, second[0].length].max
|
28
|
-
first[0] <=> second[0]
|
29
|
-
end
|
30
|
-
.each do |info|
|
31
|
-
puts "#{info[0].ljust(width)} #{info[1]}"
|
32
|
-
end
|
33
|
-
|
34
|
-
puts
|
35
|
-
puts "Math support:"
|
36
|
-
puts " - the execution environment includes the Math module."
|
37
|
-
puts " - for more info use the help math command."
|
38
|
-
|
39
|
-
puts
|
40
|
-
puts "External commands:"
|
41
|
-
puts " - executed by the system using the standard shell."
|
42
|
-
puts " - use help #{EXT_TAG} for more info on external commands."
|
27
|
+
.sort {|first, second | first[0] <=> second[0] }
|
28
|
+
.each {|info| puts "#{info[0].ljust(10)} #{info[1]}" }
|
43
29
|
puts
|
30
|
+
puts IO.read(File.dirname(__FILE__) + '/help.txt')
|
44
31
|
elsif args[0] == 'math'
|
45
32
|
puts IO.read(File.dirname(__FILE__) + '/help_math.txt')
|
33
|
+
elsif args[0] == 'ruby'
|
34
|
+
puts IO.read(File.dirname(__FILE__) + '/help_ruby.txt')
|
46
35
|
else
|
47
36
|
args[0] = "" if args[0] == EXT_TAG
|
48
37
|
system("help " + args.join)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
2) Ruby Expression support:
|
2
|
+
- any line beginning with an equals "=" sign will be evaluated as a Ruby
|
3
|
+
expression. This allows the mysh command line to serve as a programming,
|
4
|
+
debugging and super-calculator environment.
|
5
|
+
- for more info use the 'help ruby' command.
|
6
|
+
|
7
|
+
3) Math support:
|
8
|
+
- the execution environment includes the Math module.
|
9
|
+
- for more info use the 'help math' command.
|
10
|
+
|
11
|
+
4) External commands:"
|
12
|
+
- executed by the system using the standard shell.
|
13
|
+
- to force the use of the external shell, add a leading space to the command.
|
14
|
+
|
@@ -1,5 +1,9 @@
|
|
1
1
|
mysh Math support summary
|
2
2
|
|
3
|
+
- The Ruby expression execution environment includes the Math module. Thus
|
4
|
+
the following advanced math functions are directly available without having
|
5
|
+
to explicitly reference that module.
|
6
|
+
|
3
7
|
Method Returns Description
|
4
8
|
======= ======= ================================================
|
5
9
|
acos(x) Float Computes the arc cosine of x. Returns 0..PI.
|
@@ -25,8 +29,8 @@ hypot(x,y) Float Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled
|
|
25
29
|
ldexp(f,e) Float Returns the value of f*(2**e).
|
26
30
|
lgamma(x) Array Returns a two-element array containing the log of the
|
27
31
|
gamma of x and the sign of gamma of x.
|
28
|
-
log(x) Float Computes the natural log of
|
29
|
-
log(x,B) Float Computes the base B log of
|
32
|
+
log(x) Float Computes the natural log of x.
|
33
|
+
log(x,B) Float Computes the base B log of x.
|
30
34
|
log10(x) Float Returns the base 10 logarithm of x.
|
31
35
|
log2(x) Float Returns the base 2 logarithm of x.
|
32
36
|
sin(x) Float Computes the sine of x (expressed in radians).
|
@@ -0,0 +1,15 @@
|
|
1
|
+
mysh Ruby expression support summary
|
2
|
+
|
3
|
+
- All command lines that begin with an equals "=" sign are evaluated as Ruby
|
4
|
+
expressions.
|
5
|
+
- Expressions ending with a backslash character "\" are continued on the next
|
6
|
+
line. The prompt changes to "mysh\" to indicate that this is going on.
|
7
|
+
- The results are displayed using the pretty-print facility.
|
8
|
+
- Auto-complete always places any file names in quotes so they can be used
|
9
|
+
as string parameters.
|
10
|
+
|
11
|
+
A few noteworthy methods exist that facilitate use of Ruby expressions:
|
12
|
+
|
13
|
+
reset Reset the execution environment to the default state.
|
14
|
+
result Returns the result of the previous expression.
|
15
|
+
|
data/lib/mysh/expression.rb
CHANGED
@@ -11,13 +11,6 @@ module Mysh
|
|
11
11
|
|
12
12
|
include Math
|
13
13
|
|
14
|
-
#Get help info on Ruby host exec.
|
15
|
-
def self.info
|
16
|
-
[["=an_expr", "Display the result of evaluating an expression in ruby."],
|
17
|
-
["=result", "Display the result of the previous evaluation."],
|
18
|
-
["=stuff \\","This expression is continued on the next line."]]
|
19
|
-
end
|
20
|
-
|
21
14
|
#The result of the previous expression.
|
22
15
|
attr_reader :result
|
23
16
|
|
@@ -42,7 +35,12 @@ module Mysh
|
|
42
35
|
#Do the actual work of executing an expression.
|
43
36
|
def do_execute(str)
|
44
37
|
if /\\\s*$/ =~ str
|
45
|
-
|
38
|
+
parms = {
|
39
|
+
prompt: 'mysh\\ ',
|
40
|
+
auto_source: MiniReadline::QuotedFileFolderSource
|
41
|
+
}
|
42
|
+
|
43
|
+
do_execute($PREMATCH + "\n" + Mysh.input.readline(parms))
|
46
44
|
else
|
47
45
|
begin
|
48
46
|
pp eval("@result" + str)
|
@@ -55,4 +53,3 @@ module Mysh
|
|
55
53
|
end
|
56
54
|
end
|
57
55
|
end
|
58
|
-
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* array_source.rb - An array as the source for auto-complete.
|
4
|
+
module Mysh
|
5
|
+
|
6
|
+
#* array_source.rb - An array as the source for auto-complete.
|
7
|
+
class SmartSource
|
8
|
+
|
9
|
+
#Create a new file/folder auto-data source. NOP
|
10
|
+
def initialize(options)
|
11
|
+
@auto_source = MiniReadline::AutoFileSource.new(options)
|
12
|
+
@quote_source = MiniReadline::QuotedFileFolderSource.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
#Construct a new data list for auto-complete
|
16
|
+
def rebuild(str)
|
17
|
+
@active_source = str[0] == '=' ? @quote_source : @auto_source
|
18
|
+
@active_source.rebuild(str)
|
19
|
+
end
|
20
|
+
|
21
|
+
#Get the next string for auto-complete
|
22
|
+
def next
|
23
|
+
@active_source.next
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/mysh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,7 +125,9 @@ files:
|
|
125
125
|
- lib/mysh/commands/cd.rb
|
126
126
|
- lib/mysh/commands/exit.rb
|
127
127
|
- lib/mysh/commands/help.rb
|
128
|
+
- lib/mysh/commands/help.txt
|
128
129
|
- lib/mysh/commands/help_math.txt
|
130
|
+
- lib/mysh/commands/help_ruby.txt
|
129
131
|
- lib/mysh/commands/history.rb
|
130
132
|
- lib/mysh/expression.rb
|
131
133
|
- lib/mysh/internal.rb
|
@@ -133,6 +135,7 @@ files:
|
|
133
135
|
- lib/mysh/internal/instance.rb
|
134
136
|
- lib/mysh/internal/klass.rb
|
135
137
|
- lib/mysh/internal/parse.rb
|
138
|
+
- lib/mysh/smart_source.rb
|
136
139
|
- lib/mysh/version.rb
|
137
140
|
- mysh.gemspec
|
138
141
|
- rakefile.rb
|