eggsh 0.1.3 → 0.2.0
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.
- data/Gemfile +2 -1
- data/Gemfile.lock +4 -2
- data/README.rdoc +5 -5
- data/Rakefile +3 -5
- data/VERSION +1 -1
- data/bin/eggsh +0 -5
- data/eggsh.gemspec +11 -6
- data/lib/runner.rb +3 -7
- data/lib/shell.rb +10 -5
- data/lib/translator.rb +28 -5
- data/test/helper.rb +2 -7
- data/test/test_translator.rb +45 -0
- data/test/test_util.rb +18 -0
- metadata +45 -22
- data/test/test_eggsh.rb +0 -7
data/Gemfile
CHANGED
@@ -6,10 +6,11 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "
|
9
|
+
gem "bacon", ">= 0"
|
10
10
|
gem "bundler", "~> 1.0.0"
|
11
11
|
gem "jeweler", "~> 1.5.2"
|
12
12
|
gem "rcov", ">= 0"
|
13
13
|
end
|
14
14
|
|
15
15
|
gem "rb-readline"
|
16
|
+
gem "sfl"
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
bacon (1.1.0)
|
4
5
|
git (1.2.5)
|
5
6
|
jeweler (1.5.2)
|
6
7
|
bundler (~> 1.0.0)
|
@@ -9,14 +10,15 @@ GEM
|
|
9
10
|
rake (0.8.7)
|
10
11
|
rb-readline (0.4.0)
|
11
12
|
rcov (0.9.9)
|
12
|
-
|
13
|
+
sfl (2.0)
|
13
14
|
|
14
15
|
PLATFORMS
|
15
16
|
ruby
|
16
17
|
|
17
18
|
DEPENDENCIES
|
19
|
+
bacon
|
18
20
|
bundler (~> 1.0.0)
|
19
21
|
jeweler (~> 1.5.2)
|
20
22
|
rb-readline
|
21
23
|
rcov
|
22
|
-
|
24
|
+
sfl
|
data/README.rdoc
CHANGED
@@ -11,21 +11,21 @@ do this in base:
|
|
11
11
|
|
12
12
|
The solution is not so obvious , and it requires the knowledge of the tools like
|
13
13
|
grep, sed, awk, xargs ... etc. If ruby expressions are available in the command
|
14
|
-
line environment, things will be much
|
14
|
+
line environment, things will be much easier:
|
15
15
|
|
16
16
|
rm -rf { ls['*'] - ls['*.c'] }
|
17
|
-
|
17
|
+
# ruby expression inside {}
|
18
18
|
|
19
19
|
== Usage
|
20
20
|
|
21
|
-
Ruby 1.9 interpreter is required.
|
22
|
-
|
23
21
|
gem install eggsh
|
24
22
|
|
25
23
|
Call 'eggsh' to start the shell.
|
26
24
|
Settings of the shell are placed under ~/.eggshrc.
|
27
25
|
|
28
|
-
{} brackets are used to evaluate ruby expressions.
|
26
|
+
{ } brackets are used to evaluate ruby expressions.
|
27
|
+
{> } brackets are used to evaluate ruby expressions, too, except for the output
|
28
|
+
will not be executed.
|
29
29
|
|
30
30
|
== Example
|
31
31
|
|
data/Rakefile
CHANGED
@@ -26,11 +26,9 @@ Jeweler::Tasks.new do |gem|
|
|
26
26
|
end
|
27
27
|
Jeweler::RubygemsDotOrgTasks.new
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
29
|
+
desc 'Run tests'
|
30
|
+
task :test do
|
31
|
+
sh 'bacon -Itest --automatic'
|
34
32
|
end
|
35
33
|
|
36
34
|
require 'rcov/rcovtask'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/eggsh
CHANGED
data/eggsh.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{eggsh}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Liu"]
|
@@ -34,7 +34,8 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/translator.rb",
|
35
35
|
"lib/util.rb",
|
36
36
|
"test/helper.rb",
|
37
|
-
"test/
|
37
|
+
"test/test_translator.rb",
|
38
|
+
"test/test_util.rb"
|
38
39
|
]
|
39
40
|
s.homepage = %q{http://github.com/eggegg/eggsh}
|
40
41
|
s.licenses = ["MIT"]
|
@@ -43,7 +44,8 @@ Gem::Specification.new do |s|
|
|
43
44
|
s.summary = %q{An interactive shell with Ruby power}
|
44
45
|
s.test_files = [
|
45
46
|
"test/helper.rb",
|
46
|
-
"test/
|
47
|
+
"test/test_translator.rb",
|
48
|
+
"test/test_util.rb"
|
47
49
|
]
|
48
50
|
|
49
51
|
if s.respond_to? :specification_version then
|
@@ -52,20 +54,23 @@ Gem::Specification.new do |s|
|
|
52
54
|
|
53
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
56
|
s.add_runtime_dependency(%q<rb-readline>, [">= 0"])
|
55
|
-
s.
|
57
|
+
s.add_runtime_dependency(%q<sfl>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<bacon>, [">= 0"])
|
56
59
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
60
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
58
61
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
59
62
|
else
|
60
63
|
s.add_dependency(%q<rb-readline>, [">= 0"])
|
61
|
-
s.add_dependency(%q<
|
64
|
+
s.add_dependency(%q<sfl>, [">= 0"])
|
65
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
62
66
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
67
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
64
68
|
s.add_dependency(%q<rcov>, [">= 0"])
|
65
69
|
end
|
66
70
|
else
|
67
71
|
s.add_dependency(%q<rb-readline>, [">= 0"])
|
68
|
-
s.add_dependency(%q<
|
72
|
+
s.add_dependency(%q<sfl>, [">= 0"])
|
73
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
69
74
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
75
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
76
|
s.add_dependency(%q<rcov>, [">= 0"])
|
data/lib/runner.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require File.expand_path('../shell.rb', __FILE__)
|
2
|
+
require File.expand_path('../util.rb', __FILE__)
|
3
3
|
require 'readline'
|
4
4
|
|
5
5
|
module Eggsh
|
@@ -18,11 +18,7 @@ module Eggsh
|
|
18
18
|
Readline.basic_word_break_characters = ''
|
19
19
|
|
20
20
|
while line = read
|
21
|
-
|
22
|
-
@shell.exec line
|
23
|
-
else
|
24
|
-
puts 'eggsh: Unbalanced parentheses'
|
25
|
-
end
|
21
|
+
@shell.exec line
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
data/lib/shell.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sfl'
|
3
|
+
require File.expand_path('../translator.rb', __FILE__)
|
2
4
|
|
3
5
|
module Eggsh
|
4
6
|
class Shell
|
@@ -36,8 +38,11 @@ module Eggsh
|
|
36
38
|
elsif line.empty?
|
37
39
|
else
|
38
40
|
begin
|
39
|
-
|
40
|
-
|
41
|
+
shell_line = @translator.translate(line)
|
42
|
+
unless shell_line.empty?
|
43
|
+
Kernel.spawn(@env, shell_line, :chdir => @pwd)
|
44
|
+
Process.wait
|
45
|
+
end
|
41
46
|
rescue Exception => e
|
42
47
|
puts e.display
|
43
48
|
end
|
@@ -47,8 +52,8 @@ module Eggsh
|
|
47
52
|
|
48
53
|
private
|
49
54
|
def pwd arg = ''
|
50
|
-
short = @pwd.split '/'
|
51
|
-
(0...(short.size - 1)).each {|i| short[i] = short[i][0]}
|
55
|
+
short = @pwd.sub(/^#{ENV['HOME']}/, '~').split '/'
|
56
|
+
(0...(short.size - 1)).each {|i| short[i] = short[i][0..0]}
|
52
57
|
short.join '/'
|
53
58
|
end
|
54
59
|
|
data/lib/translator.rb
CHANGED
@@ -1,13 +1,36 @@
|
|
1
|
-
|
1
|
+
require File.expand_path('../ls.rb', __FILE__)
|
2
2
|
|
3
3
|
module Eggsh
|
4
4
|
class Translator
|
5
|
+
# translate a certain line with ruby expression
|
5
6
|
def translate line
|
6
|
-
|
7
|
+
eval_str, result, count = "", "", 0
|
8
|
+
for i in line.split ''
|
9
|
+
count += 1 if i == '{'
|
10
|
+
if count == 0
|
11
|
+
result += eval_part(eval_str).to_cmd + i
|
12
|
+
eval_str = ''
|
13
|
+
else
|
14
|
+
eval_str += i
|
15
|
+
end
|
16
|
+
count -= 1 if i == '}'
|
17
|
+
end
|
18
|
+
result += eval_part(eval_str).to_cmd
|
19
|
+
raise 'eggsh: Unbalanced parenthesis' if count != 0
|
20
|
+
result
|
21
|
+
end
|
7
22
|
|
8
|
-
|
9
|
-
|
10
|
-
|
23
|
+
private
|
24
|
+
def eval_part line
|
25
|
+
return '' if line.empty?
|
26
|
+
ls = Eggsh::Ls.new
|
27
|
+
if line =~ /\{\>?(.*)\}/
|
28
|
+
str = eval($1) unless line.empty?
|
29
|
+
if line =~ /\{\>(.*)\}/
|
30
|
+
return nil
|
31
|
+
else
|
32
|
+
return str
|
33
|
+
end
|
11
34
|
else
|
12
35
|
line
|
13
36
|
end
|
data/test/helper.rb
CHANGED
@@ -7,12 +7,7 @@ rescue Bundler::BundlerError => e
|
|
7
7
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
require 'eggsh'
|
11
|
+
require 'bacon'
|
12
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', '*.rb'))].each {|f| require f }
|
16
13
|
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'translator' do
|
4
|
+
before do
|
5
|
+
@translator = Eggsh::Translator.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should translate empty string' do
|
9
|
+
@translator.translate('').should.equal ''
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should translate ruby with bracket' do
|
13
|
+
@translator.translate('{ 123 }').should.equal '123'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not have problem with nested bracket' do
|
17
|
+
@translator.translate('{(1..3).to_a.join}').should.equal '123'
|
18
|
+
@translator.translate('{(0..2).to_a.map{|i| i + 1}.join}').should.equal '123'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should not evaluate expressions not in bracket' do
|
22
|
+
@translator.translate('(1..3).to_a.join').should.equal '(1..3).to_a.join'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should work with two sets of brackets' do
|
26
|
+
@translator.translate('{(0..2).to_a.map{|i| i + 1}.map{|i| i + 1}.join}').should.equal '234'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should no return with {>}' do
|
30
|
+
@translator.translate('{> 123 }').should.equal ''
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should execute within {>}' do
|
34
|
+
$TEST = nil
|
35
|
+
@translator.translate('{> $TEST = "abc"}').should.equal ''
|
36
|
+
$TEST.should.equal 'abc'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should raise error with unbalanced parenthesis' do
|
40
|
+
should.raise(RuntimeError) { @translator.translate('{') }
|
41
|
+
should.raise(RuntimeError) { @translator.translate('}') }
|
42
|
+
should.raise(RuntimeError) { @translator.translate('{}}') }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/test/test_util.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'to_cmd' do
|
4
|
+
it 'should convert array to command line with to_cmd' do
|
5
|
+
%[ab cd ef].to_cmd.should.equal 'ab cd ef'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should remain string with to_cmd' do
|
9
|
+
'abc'.to_cmd.should.equal 'abc'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'to_color' do
|
14
|
+
it 'should output color escape with red' do
|
15
|
+
'abc'.to_color(:red).should.equal "\x1b[31mabc\x1b[m"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eggsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Andrew Liu
|
@@ -18,74 +19,93 @@ date: 2011-01-25 00:00:00 +08:00
|
|
18
19
|
default_executable: eggsh
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
21
24
|
name: rb-readline
|
22
|
-
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
26
|
none: false
|
24
27
|
requirements:
|
25
28
|
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
27
31
|
segments:
|
28
32
|
- 0
|
29
33
|
version: "0"
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
30
36
|
type: :runtime
|
31
37
|
prerelease: false
|
32
|
-
|
33
|
-
|
34
|
-
name: shoulda
|
35
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
name: sfl
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
40
|
none: false
|
37
41
|
requirements:
|
38
42
|
- - ">="
|
39
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
40
45
|
segments:
|
41
46
|
- 0
|
42
47
|
version: "0"
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
43
50
|
type: :development
|
44
51
|
prerelease: false
|
45
|
-
|
52
|
+
name: bacon
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirement: *id003
|
46
63
|
- !ruby/object:Gem::Dependency
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
47
66
|
name: bundler
|
48
|
-
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
49
68
|
none: false
|
50
69
|
requirements:
|
51
70
|
- - ~>
|
52
71
|
- !ruby/object:Gem::Version
|
72
|
+
hash: 23
|
53
73
|
segments:
|
54
74
|
- 1
|
55
75
|
- 0
|
56
76
|
- 0
|
57
77
|
version: 1.0.0
|
78
|
+
requirement: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
58
80
|
type: :development
|
59
81
|
prerelease: false
|
60
|
-
version_requirements: *id003
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
82
|
name: jeweler
|
63
|
-
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
64
84
|
none: false
|
65
85
|
requirements:
|
66
86
|
- - ~>
|
67
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 7
|
68
89
|
segments:
|
69
90
|
- 1
|
70
91
|
- 5
|
71
92
|
- 2
|
72
93
|
version: 1.5.2
|
94
|
+
requirement: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
73
96
|
type: :development
|
74
97
|
prerelease: false
|
75
|
-
version_requirements: *id004
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
98
|
name: rcov
|
78
|
-
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
79
100
|
none: false
|
80
101
|
requirements:
|
81
102
|
- - ">="
|
82
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
83
105
|
segments:
|
84
106
|
- 0
|
85
107
|
version: "0"
|
86
|
-
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: *id005
|
108
|
+
requirement: *id006
|
89
109
|
description: Use Ruby expressions instead of unfriendly shell script
|
90
110
|
email: andrewliu33@gmail.com
|
91
111
|
executables:
|
@@ -111,7 +131,8 @@ files:
|
|
111
131
|
- lib/translator.rb
|
112
132
|
- lib/util.rb
|
113
133
|
- test/helper.rb
|
114
|
-
- test/
|
134
|
+
- test/test_translator.rb
|
135
|
+
- test/test_util.rb
|
115
136
|
has_rdoc: true
|
116
137
|
homepage: http://github.com/eggegg/eggsh
|
117
138
|
licenses:
|
@@ -126,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
147
|
requirements:
|
127
148
|
- - ">="
|
128
149
|
- !ruby/object:Gem::Version
|
129
|
-
hash:
|
150
|
+
hash: 3
|
130
151
|
segments:
|
131
152
|
- 0
|
132
153
|
version: "0"
|
@@ -135,6 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
156
|
requirements:
|
136
157
|
- - ">="
|
137
158
|
- !ruby/object:Gem::Version
|
159
|
+
hash: 3
|
138
160
|
segments:
|
139
161
|
- 0
|
140
162
|
version: "0"
|
@@ -147,4 +169,5 @@ specification_version: 3
|
|
147
169
|
summary: An interactive shell with Ruby power
|
148
170
|
test_files:
|
149
171
|
- test/helper.rb
|
150
|
-
- test/
|
172
|
+
- test/test_translator.rb
|
173
|
+
- test/test_util.rb
|