bashir 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,28 @@
1
+ CHANGELOG
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ bin/bashir
6
+ lib/bashir.rb
7
+ lib/bashir/api.rb
8
+ lib/bashir/commands.rb
9
+ lib/bashir/constructs.rb
10
+ lib/bashir/consts.rb
11
+ lib/bashir/core-extensions.rb
12
+ lib/bashir/evaluator.rb
13
+ lib/bashir/function.rb
14
+ lib/bashir/globals.rb
15
+ lib/bashir/persistant.rb
16
+ lib/bashir/reader.rb
17
+ lib/bashir/script.rb
18
+ lib/bashir/variable.rb
19
+ mit-license.txt
20
+ test/bs/ideas
21
+ test/bs/source1
22
+ test/data/codes
23
+ test/experiments/test-reader.rb
24
+ test/experiments/testing
25
+ test/read.rb
26
+ test/verify-api.rb
27
+ test/verify-dsl.rb
28
+ test/verify-reader.rb
@@ -0,0 +1,13 @@
1
+ = bashir
2
+
3
+ Bash with the Joy of Ruby
4
+
5
+ == Install
6
+
7
+ gem install bashir
8
+
9
+
10
+ = License
11
+
12
+ This project is released under the MIT Software License. See the provided file mit-license.txt or
13
+ http://www.opensource.org/licenses/mit-license.php
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+ require "rake"
3
+ require "echoe"
4
+
5
+ Echoe.new "bashir", "0.0.0" do | b |
6
+ b.description = "Bashir, BASH In Ruby"
7
+ b.summary = "Never, ever program in bash again"
8
+ b.url = "http://github.com/RobertDober/bashir"
9
+ b.author = "Robert Dober"
10
+ b.email = "robert.dober@gmail.com"
11
+ b.ignore_pattern = %w{ tmp/* .*.sw? }
12
+ b.development_dependencies = []
13
+ end
14
+
15
+ Dir[ File.join( File.dirname( __FILE__ ), %w{ tasks *.rake } ) ].
16
+ sort.
17
+ each do | ext |
18
+ load ext
19
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{bashir}
5
+ s.version = "0.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Robert Dober"]
9
+ s.date = %q{2009-10-30}
10
+ s.default_executable = %q{bashir}
11
+ s.description = %q{Bashir, BASH In Ruby}
12
+ s.email = %q{robert.dober@gmail.com}
13
+ s.executables = ["bashir"]
14
+ s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "bin/bashir", "lib/bashir.rb", "lib/bashir/api.rb", "lib/bashir/commands.rb", "lib/bashir/constructs.rb", "lib/bashir/consts.rb", "lib/bashir/core-extensions.rb", "lib/bashir/evaluator.rb", "lib/bashir/function.rb", "lib/bashir/globals.rb", "lib/bashir/persistant.rb", "lib/bashir/reader.rb", "lib/bashir/script.rb", "lib/bashir/variable.rb"]
15
+ s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "bin/bashir", "lib/bashir.rb", "lib/bashir/api.rb", "lib/bashir/commands.rb", "lib/bashir/constructs.rb", "lib/bashir/consts.rb", "lib/bashir/core-extensions.rb", "lib/bashir/evaluator.rb", "lib/bashir/function.rb", "lib/bashir/globals.rb", "lib/bashir/persistant.rb", "lib/bashir/reader.rb", "lib/bashir/script.rb", "lib/bashir/variable.rb", "mit-license.txt", "test/bs/ideas", "test/bs/source1", "test/data/codes", "test/experiments/test-reader.rb", "test/experiments/testing", "test/read.rb", "test/verify-api.rb", "test/verify-dsl.rb", "test/verify-reader.rb", "bashir.gemspec"]
16
+ s.homepage = %q{http://github.com/RobertDober/bashir}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bashir", "--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{bashir}
20
+ s.rubygems_version = %q{1.3.5}
21
+ s.summary = %q{Never, ever program in bash again}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ def usage
5
+ puts "usage:"
6
+ puts " #{$0} help|configure"
7
+ end
8
+
9
+ def configure
10
+ puts "setting up your bash startup file(s), source them again, or exec bash, to load the changes"
11
+ end
12
+ case ARGV.first
13
+ when /help\z/
14
+ usage
15
+ exit( -1 )
16
+ when /\Aconfig\z/
17
+ configure
18
+ else
19
+ $stderr.puts "Error missing or illegal command"
20
+ usage
21
+ exit( 1 )
22
+ end
@@ -0,0 +1,58 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ #
24
+ # All API is defined in the api subdirectory
25
+
26
+ require 'logger'
27
+
28
+ require 'bashir/globals'
29
+ require 'bashir/api'
30
+ require 'bashir/commands'
31
+ require 'bashir/core-extensions'
32
+ require 'bashir/reader'
33
+
34
+ #
35
+ # In this topfile we only implement the main API constructurs
36
+ #
37
+ module Bashir
38
+ File.unlink( "bashir.log" ) rescue nil
39
+ @logger = Logger::new( "bashir.log", 2, 1 << 23 )
40
+ @logger.formatter = " "
41
+ class << self
42
+ include Reader
43
+ def __log *msg
44
+ msg.each do | one_msg |
45
+ @logger.info one_msg
46
+ end
47
+ end
48
+ end
49
+ end
50
+ begin
51
+ loop do
52
+ x = Bashir::read_line
53
+ system( x )
54
+ break if x.nil?
55
+ end
56
+ rescue Interrupt
57
+ puts "<C-C> ends bashir command, bye for now"
58
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ %w{ constructs function script variable }.each do | mod |
24
+ require "bashir/#{mod}"
25
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/commands.rb
4
+ #
5
+
6
+ require 'bashir/persistant'
7
+ @variables = Hash::new
8
+
9
+ def set_variable name, args
10
+ @variables[ name.to_sym ] = args.join( " " )
11
+
12
+ end
13
+
14
+ def execute_command cmd, *args
15
+ case cmd
16
+ when /\A_sys\Z/
17
+ system args.join( " " )
18
+ when /\A\w+=\Z/
19
+ set_variable cmd.sub(/=\Z/, ""), args
20
+ store @variables
21
+ args
22
+ when "first"
23
+
24
+ puts args.first
25
+
26
+ when "get"
27
+ @variables = retrieve
28
+ puts @variables[ args.first.to_sym ]
29
+
30
+ when "set"
31
+ eval_in_sandbox args.join( " " )
32
+ else
33
+ $stderr.puts "Bashir: Illegal Command \"#{cmd}\""
34
+ exit 1
35
+ end
36
+ end
37
+
38
+ module Bashir
39
+ module Commands
40
+ AllCommands = { ls: "ls --color=auto", vi: "/usr/bin/vi" }
41
+ def _command? word
42
+ AllCommands[ word.to_sym ]
43
+ end
44
+ end
45
+ end
46
+
47
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,36 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+
24
+ module Bashir
25
+ IllegalConstruct = Class::new StandardError
26
+ LegalConstructs = %w{ case for if while }
27
+ class Construct
28
+ private
29
+ def initialize constr_type
30
+ raise IllegalConstruct, "cannot create a construct of type #{constr_type}" unless
31
+ LegalConstructs.include? constr_type.to_s
32
+ end
33
+ end
34
+ end
35
+
36
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,34 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/consts.rb
4
+
5
+
6
+ module Bashir
7
+ module Reader
8
+
9
+ ReadExit = Class::new RuntimeError
10
+ SwitchToRubyMode = Class::new RuntimeError
11
+
12
+ module Codes
13
+ BS = 127
14
+ Space = 32
15
+ EOL = 13
16
+ Tab = 9
17
+ Back = 8
18
+ end
19
+
20
+ Space = " "
21
+
22
+ EOLRgx = /\n\r?/
23
+ WhitespaceRgx = /\s/
24
+
25
+ SpecialCodes = [*33..64, *91..94, *123..126]
26
+ class << SpecialCodes
27
+ def === other
28
+ include? other
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,11 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/core-extensions.rb
4
+
5
+ class String
6
+ def drop n=1
7
+ self[-[size,n].min..-1]=""
8
+ end
9
+ end
10
+
11
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,9 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/evaluator.rb
4
+
5
+ def eval_in_sandbox cmd
6
+ Sandbox.instance_eval cmd
7
+ end
8
+
9
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,44 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Bashir
24
+ class Function
25
+ def as_bash indent=nil
26
+ %<function #{@name}
27
+ {
28
+ > + body_as_bash + %<}>
29
+ end
30
+ def name; "#@name" end
31
+
32
+ private
33
+ def body_as_bash
34
+ ""
35
+ end
36
+
37
+ def initialize name, in_script=nil
38
+ @name = name
39
+ @in_script = in_script
40
+ end
41
+ end
42
+ end
43
+
44
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,7 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/globals.rb
4
+
5
+ StoreURL = "#{ENV[ "HOME" ]}/tmp/bashir.persistant"
6
+
7
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,15 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/persistant.rb
4
+
5
+ def retrieve
6
+ Marshal.load( File.open( StoreURL ) )
7
+ end
8
+
9
+ def store data
10
+ File.open StoreURL, "w" do | f |
11
+ Marshal.dump data, f
12
+ end
13
+ end
14
+
15
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,123 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/reader.rb
4
+
5
+ require 'highline/system_extensions'
6
+
7
+ require 'bashir/consts'
8
+
9
+ module Bashir
10
+ module Reader
11
+ include HighLine::SystemExtensions
12
+ include Bashir::Commands
13
+
14
+ def echo char
15
+ print char if char
16
+ end
17
+ def read_up_to delim = /\s/, echo = true, escapes =
18
+ [].tap{ | result |
19
+ loop do
20
+ ch = _read
21
+ result << ch
22
+ p ch
23
+ print ch.chr
24
+ break if delim === ch.chr
25
+ end
26
+ }
27
+ end
28
+
29
+ def read_command_line start
30
+ __log ">>>read_command_line #{start}"
31
+ result = start.chr
32
+ _read_with_handlers( result,
33
+ Codes::Tab => lambda{ | read_sofar, ch | __log "caught <Tab>"
34
+ ""
35
+ },
36
+ Codes::EOL => lambda{ | read_sofar, ch | __log "caught <CR>"
37
+ print ch.chr
38
+ _exit_read
39
+ },
40
+ Codes::BS => lambda{ | read_sofar, ch | __log "caught <BS>"
41
+ print( Codes::Back.chr + Space + Codes::Back.chr ) unless read_sofar.empty?
42
+ read_sofar.drop
43
+ },
44
+ Codes::Space => lambda{ | read_so_far, ch | __log "end of command"
45
+ print ch.chr
46
+ read_so_far.replace( _check_command read_so_far )
47
+ __log "replaced: #{read_so_far}"
48
+ ch.chr
49
+ }
50
+ )
51
+ rescue SwitchToRubyMode
52
+ _finish_command_in_rb_mode result
53
+ rescue ReadExit
54
+ __log "<<<read_command_line: #{result}"
55
+ result
56
+ end
57
+
58
+ def read_line
59
+ __log ">>>read_line"
60
+ result = ""
61
+ ch = _skip_chars( end: EOLRgx, skip: WhitespaceRgx )
62
+ case ch
63
+ when SpecialCodes
64
+ __log "special #{ch}"
65
+ read_special ch
66
+ else
67
+ __log "start parsing"
68
+ read_command_line ch
69
+ end
70
+ rescue Interrupt
71
+ return nil
72
+ end # read_line
73
+
74
+ def read_special special_char
75
+ __log ">>>read_special #{special_char}"
76
+ end
77
+
78
+ private
79
+ def _check_command word
80
+ _command?( word ).tap{ | real_command |
81
+ raise SwithToRubyMode, "#{word} is not a command" unless real_command
82
+ }
83
+ end
84
+ def _exit_read
85
+ raise ReadExit, "I got a exit handler"
86
+ end
87
+ def _read
88
+ get_character.tap do | ch |
89
+ __log "raw char read: #{ch}"
90
+ end
91
+ end
92
+
93
+ def _finish_command_in_rb_mode sofar
94
+ puts "Sorry Ruby Mode not implemented yet"
95
+ end
96
+
97
+ def _read_with_handlers r, handlers={}
98
+ __log '>>>_read_with_handlers'
99
+ loop do
100
+ ch = _read
101
+ hdler = handlers[ ch ]
102
+ __log "c: #{hdler.inspect}"
103
+ if hdler then
104
+ r << hdler[ r, ch ]
105
+ else
106
+ print ch.chr
107
+ r << ch.chr
108
+ end
109
+ __log "read so far: \"#{r}\""
110
+ end
111
+ end
112
+ def _skip_chars params={}
113
+ loop do
114
+ ch = _read
115
+ print ch.chr
116
+ return "" if params[ :end ] === ch.chr
117
+ return ch unless params[ :skip ] === ch.chr
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ # vim: sts=3 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,28 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Bashir
24
+ class Script
25
+ end
26
+ end
27
+
28
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,35 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Bashir
24
+ class Variable
25
+ attr_reader :value
26
+ private
27
+ def initialize name, value="", type=:local
28
+ @name = name
29
+ @value = value.to_s
30
+ @type = type
31
+ end
32
+ end
33
+ end
34
+
35
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ Hirarchical variables, probably using openobject
2
+ core.rr.lines
3
+
4
+ % Notation to limits
5
+ puts %f/*x.rb/
6
+ puts %f *x.rb # The whitespace became a delimiter
@@ -0,0 +1,5 @@
1
+ # vim: sts=4 sw=4 expandtab tw=0 ft=sh :
2
+ export BASHIR_HOME=/home/robert/git/ruby/bashir
3
+ export BASHIR_LIB=${BASHIR_HOME}/lib
4
+ alias .='ruby -I${BASHIR_LIB} ${BASHIR_LIB}/bashir.rb '
5
+ alias @='ruby -I${BASHIR_LIB} ${BASHIR_LIB}/bashir.rb get '
Binary file
@@ -0,0 +1,11 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/test/experiments/test-reader.rb
4
+
5
+ $:.unshift( File::join( File::dirname( __FILE__ ), "..", "..", "lib" ) )
6
+
7
+ require 'bashir/reader'
8
+
9
+ include Bashir::Reader
10
+
11
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,5 @@
1
+ # vim: sw=4 sts=4 expandtab tw=0 ft=sh:
2
+ function rby
3
+ {
4
+ eval "$( echo "$*" | ruby )"
5
+ }
@@ -0,0 +1,18 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/lib/bashir/reader.rb
4
+
5
+ require 'highline/system_extensions'
6
+
7
+ include HighLine::SystemExtensions
8
+
9
+ def read_upto endset = [ 13 ]
10
+ loop do
11
+ ch = get_character
12
+ puts ch
13
+ puts ch.chr
14
+ return if endset === ch
15
+ end
16
+ end
17
+
18
+ read_upto
@@ -0,0 +1,73 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'lab419/tools/verify'
24
+ require 'lab419/tools/mockify'
25
+ project_home_directory = ENV[ "project_home" ]
26
+ $:.unshift( File::join( project_home_directory, "lib" ) )
27
+
28
+ require 'bashir'
29
+
30
+ Verify "existence" do
31
+ verify "shell instances can be created" do
32
+ Bashir::Script::new
33
+ end
34
+ verify "function instances can be created" do
35
+ Bashir::Function::new :dummy
36
+ end
37
+ verify "functions have sticky names" do
38
+ Bashir::Function::new( :fourtytwo ).name == "fourtytwo"
39
+ end
40
+ verify "functions have string representations" do
41
+ Bashir::Function::new( :alpha ).as_bash == %<function alpha
42
+ {
43
+ }>
44
+ end
45
+
46
+ verify "variables can be created" do
47
+ Bashir::Variable::new :x, 42
48
+ end
49
+
50
+ verify "variables can be read" do
51
+ Bashir::Variable::new( :y, 42 ).value == "42"
52
+ end
53
+
54
+ verify "constructs can be created" do
55
+ Bashir::Construct::new( :case )
56
+ Bashir::Construct::new( :for )
57
+ Bashir::Construct::new( :if )
58
+ Bashir::Construct::new( :while )
59
+ end
60
+
61
+ verify_exceptions Bashir::IllegalConstruct do
62
+ Bashir::Construct::new( :xxx )
63
+ end
64
+
65
+ end
66
+
67
+ Verify "API for variables" do
68
+ %w{ local global script exported }.each do | var_type |
69
+ v = Bashir::Variable::new :a, 42, var_type
70
+ end
71
+ end
72
+
73
+ # vim: sts=2 sw=2 ft=verify expandtab nu :
@@ -0,0 +1,24 @@
1
+ #!/usr/local/bin/ruby -w
2
+ Copyright (c) 2009 Robert Dober <author.downcase.sub(" ", ".") + "@gmail.com">
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+ # encoding: utf-8
22
+
23
+
24
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
@@ -0,0 +1,39 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # encoding: utf-8
3
+ # file: /home/robert/git/ruby/bashir/test/verify-reader.rb
4
+
5
+ require 'tempfile'
6
+
7
+ $:.unshift( File::join( File::dirname( __FILE__ ), %w{ .. lib } ) )
8
+
9
+
10
+ require 'bashir/reader'
11
+ include Bashir::Reader
12
+ MYSELF = "ruby #{__FILE__}"
13
+
14
+ def echo_into echo_string, testcase
15
+ t = Tempfile::new( testcase )
16
+ t.print echo_string
17
+ system %<cat #{t.path} | #{MYSELF} #{testcase}>
18
+ end
19
+
20
+ def execute_tests
21
+ echo_into "abcd ef", "1"
22
+ end
23
+
24
+ case ARGV.first
25
+ when nil
26
+ execute_tests
27
+ when "1"
28
+ require 'mockify'
29
+ require 'verify'
30
+ Verify "read up to" do
31
+ verify msg: "read up to space",
32
+ target: "abcd ".split("").map(&:ord),
33
+ actual: read_up_to
34
+ end
35
+ else
36
+ raise RuntimeError, "testcase not supported: #{ARGV.first}"
37
+ end
38
+
39
+ # vim: sts=2 sw=2 ft=ruby expandtab nu :
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bashir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Dober
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-30 00:00:00 +01:00
13
+ default_executable: bashir
14
+ dependencies: []
15
+
16
+ description: Bashir, BASH In Ruby
17
+ email: robert.dober@gmail.com
18
+ executables:
19
+ - bashir
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGELOG
24
+ - README.rdoc
25
+ - bin/bashir
26
+ - lib/bashir.rb
27
+ - lib/bashir/api.rb
28
+ - lib/bashir/commands.rb
29
+ - lib/bashir/constructs.rb
30
+ - lib/bashir/consts.rb
31
+ - lib/bashir/core-extensions.rb
32
+ - lib/bashir/evaluator.rb
33
+ - lib/bashir/function.rb
34
+ - lib/bashir/globals.rb
35
+ - lib/bashir/persistant.rb
36
+ - lib/bashir/reader.rb
37
+ - lib/bashir/script.rb
38
+ - lib/bashir/variable.rb
39
+ files:
40
+ - CHANGELOG
41
+ - Manifest
42
+ - README.rdoc
43
+ - Rakefile
44
+ - bin/bashir
45
+ - lib/bashir.rb
46
+ - lib/bashir/api.rb
47
+ - lib/bashir/commands.rb
48
+ - lib/bashir/constructs.rb
49
+ - lib/bashir/consts.rb
50
+ - lib/bashir/core-extensions.rb
51
+ - lib/bashir/evaluator.rb
52
+ - lib/bashir/function.rb
53
+ - lib/bashir/globals.rb
54
+ - lib/bashir/persistant.rb
55
+ - lib/bashir/reader.rb
56
+ - lib/bashir/script.rb
57
+ - lib/bashir/variable.rb
58
+ - mit-license.txt
59
+ - test/bs/ideas
60
+ - test/bs/source1
61
+ - test/data/codes
62
+ - test/experiments/test-reader.rb
63
+ - test/experiments/testing
64
+ - test/read.rb
65
+ - test/verify-api.rb
66
+ - test/verify-dsl.rb
67
+ - test/verify-reader.rb
68
+ - bashir.gemspec
69
+ has_rdoc: true
70
+ homepage: http://github.com/RobertDober/bashir
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --line-numbers
76
+ - --inline-source
77
+ - --title
78
+ - Bashir
79
+ - --main
80
+ - README.rdoc
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "1.2"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project: bashir
98
+ rubygems_version: 1.3.5
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Never, ever program in bash again
102
+ test_files: []
103
+