cosine-brush 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/brush +5 -0
  2. data/lib/brush.rb +42 -0
  3. metadata +57 -0
data/bin/brush ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'brush'
4
+
5
+ Brush::Shell.new.start
data/lib/brush.rb ADDED
@@ -0,0 +1,42 @@
1
+
2
+ module Brush
3
+ class Shell
4
+ DEFAULT_EXEC_MATCH = %r"^(\S.*)"
5
+ DEFAULT_RUBY_MATCH = %r"^\s+(.*)"
6
+ DEFAULT_PS1 = "% "
7
+ DEFAULT_PS2 = "%-"
8
+ DEFAULT_RPS1 = "\#=> "
9
+ DEFAULT_RPS2 = "\# > "
10
+
11
+ def initialize (inp = $stdin, out = $stdout, err = $stderr, binding = nil)
12
+ @in, @out, @err = inp, out, err
13
+ @exec_match = DEFAULT_EXEC_MATCH
14
+ @ruby_match = DEFAULT_RUBY_MATCH
15
+ @ps1, @ps2 = DEFAULT_PS1, DEFAULT_PS2
16
+ @rps1, @rps2 = DEFAULT_RPS1, DEFAULT_RPS2
17
+ @binding ||= binding
18
+ @out.sync = true
19
+ @err.sync = true
20
+ end
21
+
22
+ def start
23
+ while not @in.eof?
24
+ @out.print @ps1
25
+ line = @in.gets.chomp
26
+ if line =~ @ruby_match
27
+ repl line[@ruby_match, 1]
28
+ elsif line =~ @exec_match
29
+ system line[@exec_match, 1]
30
+ else
31
+ repl line
32
+ end
33
+ end
34
+ end
35
+
36
+ def repl (code)
37
+ result = eval(code, @binding)
38
+ @out.puts "#{@rps1}#{result.inspect}"
39
+ end
40
+ end
41
+ end
42
+
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cosine-brush
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael H Buselli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Brush is intended to be an interactive shell with the power of Ruby. As it is in its infancy, it is very basic and much of the functionality is implemented by scaffolding that will later be replaced. For instance, presently commands are passed off to another shell for execution, but eventually all globing, pipe setup, forking, and execing will be handled directly by Brush.
17
+ email:
18
+ - cosine@cosine.org
19
+ - michael@buselli.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - bin/brush
28
+ - lib/brush.rb
29
+ has_rdoc: true
30
+ homepage: http://cosine.org/ruby/brush/
31
+ licenses:
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project: brush
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: "Brush \xE2\x80\x94 the Bourne RUby SHell"
56
+ test_files: []
57
+