chitin 1.0.3 → 1.0.4
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/ANNOUNCEMENT +2 -0
- data/LICENSE +22 -0
- data/README +3 -3
- data/TODO +10 -0
- data/bin/chitin +2 -7
- data/lib/chitin.rb +4 -4
- data/lib/chitin/commands/builtins.rb +43 -13
- data/lib/chitin/commands/executable.rb +41 -34
- data/lib/chitin/commands/pipe.rb +2 -1
- data/lib/chitin/commands/ruby.rb +2 -4
- data/lib/chitin/commands/runnable.rb +42 -36
- data/lib/chitin/core_ext/coolline.rb +2 -0
- data/lib/chitin/core_ext/object.rb +1 -0
- data/lib/chitin/core_ext/string.rb +38 -0
- data/lib/chitin/file.rb +14 -1
- data/lib/chitin/sandbox.rb +1 -1
- data/lib/chitin/session.rb +11 -13
- data/lib/chitin/version.rb +1 -1
- metadata +3 -2
data/ANNOUNCEMENT
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright 2013 Ari Brown. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
7
|
+
list of conditions and the following disclaimer.
|
8
|
+
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY Ari Brown "AS IS" AND ANY EXPRESS OR IMPLIED
|
14
|
+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
15
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
16
|
+
EVENT SHALL Ari Brown OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
17
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
20
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
21
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
CHANGED
@@ -238,7 +238,7 @@ Congratulations! You are now a second class scout!
|
|
238
238
|
|
239
239
|
Alright, hotshot. Let's see if you've got what it takes to be first class.
|
240
240
|
Your boss rolls into your office and asks to speak with you. You know it
|
241
|
-
couldn't be about your
|
241
|
+
couldn't be about your pokemon collection because you fixed that in attaining
|
242
242
|
second class; now he just thinks you're a nerd for having a 40GB digimon
|
243
243
|
collection. So bossman rolls in and says "Yo dawg, delete every file and folder
|
244
244
|
in a directory." Naturally, he decides not to open up a GUI and do that himself
|
@@ -309,7 +309,7 @@ do this here because tar does NOT want any dashes.
|
|
309
309
|
So back to the installation process:
|
310
310
|
|
311
311
|
ari: ~/src/chitin % here 'configure', :prefix => '/Users/ari/local'
|
312
|
-
ari: ~/src/chitin % make
|
312
|
+
ari: ~/src/chitin % [make, make.install]
|
313
313
|
|
314
314
|
`here` is the method we use to refer to an executable file relative to the
|
315
315
|
current directory. We're using hash notation in configure to automatically
|
@@ -374,7 +374,7 @@ The string methods which take precedence over executables are:
|
|
374
374
|
pack
|
375
375
|
unpack
|
376
376
|
|
377
|
-
== Globbing:
|
377
|
+
== Globbing: Globlins and Hobgloblins
|
378
378
|
|
379
379
|
Globbing is simple in Chitin: there is none. However, that's ok because
|
380
380
|
globbing is a really really cheap hack. So here's what Chitin offers in its
|
data/TODO
CHANGED
@@ -4,12 +4,22 @@ FUTURE:
|
|
4
4
|
* remove/edit history
|
5
5
|
-> important for removing passwords if accidentally typed
|
6
6
|
* improve library usage of executables
|
7
|
+
* interprocess communication
|
8
|
+
-> sharing of variables between chitin processes
|
9
|
+
* remove trailing whitespace from lines somehow. maybe as a final transformation when you hit enter?
|
10
|
+
* `other_ls = method(:ls)` would be cool. note that ls is mapped to a binary and is not actually a method
|
11
|
+
* pass environment to child processes
|
12
|
+
* tab complete ruby/shell things
|
7
13
|
|
8
14
|
QUIRKS:
|
9
15
|
* menu doesn't erase itself sometimes
|
10
16
|
-> cat and tabcomplete a file that is empty. output is correct but confusing
|
17
|
+
* does not play nice with GDB if it is called within the bash profile file
|
11
18
|
|
12
19
|
FAILURES:
|
20
|
+
* ^C on running ruby programs kills the whole interpreter... womp.
|
21
|
+
* slashes in filenames
|
22
|
+
* `include Math; sin(5)` fails
|
13
23
|
|
14
24
|
Questions:
|
15
25
|
* Why do you have to do @line = '' in Coolline in order to not affect the
|
data/bin/chitin
CHANGED
@@ -11,13 +11,8 @@ end
|
|
11
11
|
|
12
12
|
require File.join(File.dirname(follow_link(__FILE__)), "..", "lib", "chitin")
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
rc = ARGV[0]
|
17
|
-
else
|
18
|
-
FileUtils.touch File.expand_path('~/.chitinrc')
|
19
|
-
rc = File.expand_path('~/.chitinrc')
|
20
|
-
end
|
14
|
+
rc = ARGV[0] || File.expand_path('~/.chitinrc')
|
15
|
+
FileUtils.touch rc
|
21
16
|
|
22
17
|
Chitin::Builtins.class_eval File.read(rc)
|
23
18
|
|
data/lib/chitin.rb
CHANGED
@@ -2,6 +2,10 @@ def need(file)
|
|
2
2
|
require(File.dirname(File.expand_path(__FILE__)) + '/' + file)
|
3
3
|
end
|
4
4
|
|
5
|
+
require 'date'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'pp'
|
8
|
+
|
5
9
|
need 'chitin/version'
|
6
10
|
need 'chitin/support'
|
7
11
|
need 'chitin/file'
|
@@ -20,7 +24,3 @@ need 'chitin/tools/string_methods'
|
|
20
24
|
need 'chitin/sandbox'
|
21
25
|
need 'chitin/session'
|
22
26
|
|
23
|
-
require 'date'
|
24
|
-
require 'fileutils'
|
25
|
-
require 'pp'
|
26
|
-
|
@@ -45,11 +45,6 @@ module Chitin
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# L for Lambda. Creates a proc as a RubyMethod
|
49
|
-
def L(&block)
|
50
|
-
StringMethod.new :bottle, &block
|
51
|
-
end
|
52
|
-
|
53
48
|
# ruby's backtick doesn't chomp off the newline, which makes it more
|
54
49
|
# or less useless for piping into other commands
|
55
50
|
def `(args); super(args).chomp; end
|
@@ -77,6 +72,17 @@ module Chitin
|
|
77
72
|
end
|
78
73
|
end
|
79
74
|
|
75
|
+
# Do nothing. this is so that we don't accidentally delete a word we're trying to quote
|
76
|
+
bind(?\C-w) {}
|
77
|
+
|
78
|
+
# Automatically add *f(..) around something
|
79
|
+
bind ?\C-f do |c|
|
80
|
+
if beg = c.word_beginning_before(c.pos) and last = c.word_end_before(c.pos)
|
81
|
+
c.line[beg..last] = '*f(' + c.line[beg..last] + ')'
|
82
|
+
c.pos = last + 5 # 4 for the characters and 1 for the cursor
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
80
86
|
# Clear the line, don't add it to history
|
81
87
|
bind ?\C-g do |c|
|
82
88
|
c.line.clear
|
@@ -124,6 +130,21 @@ module Chitin
|
|
124
130
|
|
125
131
|
def gem(*a); raw_exec("gem", *a); end
|
126
132
|
def all; D('.'); end
|
133
|
+
|
134
|
+
def to_num; L {|i| i.to_i }; end
|
135
|
+
def p(*args)
|
136
|
+
args.map do |arg|
|
137
|
+
if Runnable === arg
|
138
|
+
puts arg[:inspect]
|
139
|
+
else
|
140
|
+
puts arg.inspect
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# i know puts returns nil, but this is to emphasize
|
145
|
+
# the fact that we want it to return nil
|
146
|
+
nil
|
147
|
+
end
|
127
148
|
end
|
128
149
|
include Aliases
|
129
150
|
|
@@ -157,6 +178,21 @@ module Chitin
|
|
157
178
|
end
|
158
179
|
|
159
180
|
def method_missing(name, *args, &block)
|
181
|
+
if meth = lookup(name, *args, &block)
|
182
|
+
return meth
|
183
|
+
end
|
184
|
+
|
185
|
+
# If we made it this far, there is no executable to be had. Super it up.
|
186
|
+
super
|
187
|
+
end
|
188
|
+
|
189
|
+
def raw_exec(path, *args)
|
190
|
+
Executable.new path, *args
|
191
|
+
end
|
192
|
+
alias_method :here, :raw_exec
|
193
|
+
alias_method :h, :raw_exec
|
194
|
+
|
195
|
+
def lookup(name, *args, &block)
|
160
196
|
if PRIORITY_METHODS.include? name
|
161
197
|
return StringMethod.new(name, *args, &block)
|
162
198
|
end
|
@@ -168,15 +204,9 @@ module Chitin
|
|
168
204
|
if "".public_methods(false).include? name
|
169
205
|
return StringMethod.new(name, *args, &block)
|
170
206
|
end
|
171
|
-
|
172
|
-
|
173
|
-
super
|
174
|
-
end
|
175
|
-
|
176
|
-
def raw_exec(path, *args)
|
177
|
-
Executable.new path, *args
|
207
|
+
|
208
|
+
nil
|
178
209
|
end
|
179
|
-
alias_method :here, :raw_exec
|
180
210
|
end
|
181
211
|
include ExecutableBinaries
|
182
212
|
|
@@ -5,15 +5,12 @@ module Chitin
|
|
5
5
|
include Runnable
|
6
6
|
|
7
7
|
def initialize(path, *args)
|
8
|
+
super()
|
9
|
+
|
8
10
|
@path = path
|
9
11
|
@args = process_args(args)
|
10
12
|
end
|
11
13
|
|
12
|
-
def |(other)
|
13
|
-
Pipe.new self, other
|
14
|
-
end
|
15
|
-
alias_method :<=>, :|
|
16
|
-
|
17
14
|
# EVERYTHING will be sent to the command. ERRTHANG!!!!
|
18
15
|
def method_missing(name, *arr, &blk)
|
19
16
|
setup name.to_s, *process_args(arr)
|
@@ -30,18 +27,37 @@ module Chitin
|
|
30
27
|
processed = args.map do |arg|
|
31
28
|
if arg.is_a? Hash
|
32
29
|
arg.map do |k, v|
|
33
|
-
if k.is_a? Symbol
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
key = if k.is_a? Symbol
|
31
|
+
"#{k.to_s.size > 1 ? '--' : '-'}#{k}"
|
32
|
+
else
|
33
|
+
k
|
34
|
+
end
|
35
|
+
|
36
|
+
val = v.is_a?(FSObject) ? v.to_a : v
|
37
|
+
|
38
|
+
[key, val]
|
38
39
|
end
|
39
40
|
else
|
40
|
-
|
41
|
+
# I'm leaving this here so that I know what went down in this
|
42
|
+
# battlefield. I tried automatically expanding globs, but that
|
43
|
+
# in conjunction with * means things get expanded twice, resulting
|
44
|
+
# in a lot of duplicates.
|
45
|
+
#
|
46
|
+
# Maybe an answer is to get rid of * and only do automatic expansion
|
47
|
+
# for executables.
|
48
|
+
#
|
49
|
+
# NO YOU CAN'T! What if you want to pass a directory to program that
|
50
|
+
# you have save as a Chitin::Directory? It would end up being globbed
|
51
|
+
# open which is NOT what you wanted. Globbing must be done explicitly.
|
52
|
+
#
|
53
|
+
# a = arg.is_a?(FSObject) ? arg.to_a : arg
|
54
|
+
# pp a.map(&:to_s) if arg.is_a? FSObject
|
55
|
+
# a
|
56
|
+
arg
|
41
57
|
end
|
42
58
|
end
|
43
59
|
|
44
|
-
processed.flatten
|
60
|
+
processed.flatten.map {|a| a.to_s }
|
45
61
|
end
|
46
62
|
|
47
63
|
def args
|
@@ -61,9 +77,6 @@ module Chitin
|
|
61
77
|
:io
|
62
78
|
end
|
63
79
|
|
64
|
-
# TODO fix it so that self.err isn't alone in the whole `if self.err`
|
65
|
-
# bit. figure out a good way to make it default or something. i dunno.
|
66
|
-
# just do it.
|
67
80
|
def run
|
68
81
|
child = fork do
|
69
82
|
# Like the comments in +open_pipes+, the user writes to +@in+.
|
@@ -71,14 +84,13 @@ module Chitin
|
|
71
84
|
# since executables normally read from STDIN, we can link them.
|
72
85
|
IO.open(0).reopen self[:in] # STDIN to the program comes from
|
73
86
|
IO.open(1).reopen self[:out]
|
74
|
-
IO.open(2).reopen self[:err]
|
87
|
+
IO.open(2).reopen self[:err]
|
75
88
|
|
76
|
-
|
77
|
-
|
78
|
-
|
89
|
+
# These can be closed because there is already an opening
|
90
|
+
# via IO 0, 1, and 2.
|
91
|
+
close_all
|
79
92
|
# And it is important that they be closed, otherwise
|
80
93
|
# we'll have a hanging pipe that will hold everything up.
|
81
|
-
# In the future, we'll use `close_all` to make it simple.
|
82
94
|
|
83
95
|
exec path, *args
|
84
96
|
end
|
@@ -97,7 +109,14 @@ module Chitin
|
|
97
109
|
|
98
110
|
def reset
|
99
111
|
@opened = false
|
112
|
+
|
113
|
+
# these set them to nil (duh)
|
100
114
|
self.in, self.out, self.err = nil
|
115
|
+
|
116
|
+
# so that THESE can then reopen them
|
117
|
+
set_in STDIN
|
118
|
+
set_out STDOUT
|
119
|
+
set_err STDERR
|
101
120
|
end
|
102
121
|
|
103
122
|
def each_line
|
@@ -119,23 +138,11 @@ module Chitin
|
|
119
138
|
end
|
120
139
|
|
121
140
|
def inspect
|
122
|
-
"#<Chitin::Executable
|
141
|
+
"#<Chitin::Executable #{super}>"
|
123
142
|
end
|
124
143
|
|
125
144
|
def to_s
|
126
|
-
arr = args
|
127
|
-
if arg.is_a? Hash
|
128
|
-
arg.map do |k, v|
|
129
|
-
if k.is_a? Symbol
|
130
|
-
["#{k.to_s.size > 1 ? '--' : '-'}#{k}", v.to_s]
|
131
|
-
else
|
132
|
-
[k.to_s, v.to_s]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
else
|
136
|
-
arg.to_s
|
137
|
-
end
|
138
|
-
end
|
145
|
+
arr = process_args(args)
|
139
146
|
|
140
147
|
[path, *arr.flatten].join ' '
|
141
148
|
end
|
data/lib/chitin/commands/pipe.rb
CHANGED
data/lib/chitin/commands/ruby.rb
CHANGED
@@ -8,16 +8,14 @@ module Chitin
|
|
8
8
|
attr_reader :pid
|
9
9
|
|
10
10
|
def initialize(*arr, &block)
|
11
|
+
super()
|
12
|
+
|
11
13
|
raise "Need at least a method name" unless [String, Symbol].include? arr.first.class
|
12
14
|
@chains = []
|
13
15
|
latest = [*arr]
|
14
16
|
latest << block if block
|
15
17
|
@chains << latest
|
16
18
|
end
|
17
|
-
|
18
|
-
def |(other)
|
19
|
-
Pipe.new self, other
|
20
|
-
end
|
21
19
|
|
22
20
|
def method_missing(*arr, &block)
|
23
21
|
latest = [*arr]
|
@@ -1,6 +1,12 @@
|
|
1
1
|
module Chitin
|
2
2
|
module Runnable
|
3
3
|
|
4
|
+
def initialize
|
5
|
+
set_in STDIN
|
6
|
+
set_out STDOUT
|
7
|
+
set_err STDERR
|
8
|
+
end
|
9
|
+
|
4
10
|
def <(io)
|
5
11
|
case io
|
6
12
|
when IO, File
|
@@ -73,6 +79,10 @@ module Chitin
|
|
73
79
|
|
74
80
|
def bg!; @bg = true; self; end
|
75
81
|
def bg?; @bg; end
|
82
|
+
def fg?; !@bg; end
|
83
|
+
|
84
|
+
def |(other); Pipe.new self, other; end
|
85
|
+
alias_method :<=>, :|
|
76
86
|
|
77
87
|
private
|
78
88
|
|
@@ -80,57 +90,53 @@ module Chitin
|
|
80
90
|
attr_accessor :in
|
81
91
|
attr_accessor :out
|
82
92
|
attr_accessor :err
|
83
|
-
|
84
|
-
def returning
|
85
|
-
raise "Not Yet Implemented"
|
86
|
-
end
|
87
|
-
|
88
|
-
# Generally the same as +run+, except for the ruby commands
|
89
|
-
# they return real ruby that can be given back to the user.
|
90
|
-
def raw_run
|
91
|
-
run
|
92
|
-
end
|
93
93
|
|
94
|
+
# I'm pretty sure this would induce a memory leak if Ruby
|
95
|
+
# weren't GCed. Suggestions are appreciated.
|
94
96
|
def set_in(other)
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
self[:in=, r]
|
99
|
-
end
|
97
|
+
r, w = IO.pipe
|
98
|
+
w.close
|
99
|
+
self[:in=, r]
|
100
100
|
self[:in].reopen other
|
101
101
|
end
|
102
102
|
|
103
|
+
# I'm pretty sure this would induce a memory leak if Ruby
|
104
|
+
# weren't GCed. Suggestions are appreciated.
|
103
105
|
def set_out(other)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
self[:out=, w]
|
108
|
-
end
|
106
|
+
r, w = IO.pipe
|
107
|
+
r.close
|
108
|
+
self[:out=, w]
|
109
109
|
self[:out].reopen other
|
110
110
|
end
|
111
111
|
|
112
|
+
# I'm pretty sure this would induce a memory leak if Ruby
|
113
|
+
# weren't GCed. Suggestions are appreciated.
|
112
114
|
def set_err(other)
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
self[:err=, w]
|
117
|
-
end
|
115
|
+
r, w = IO.pipe
|
116
|
+
r.close
|
117
|
+
self[:err=, w]
|
118
118
|
self[:err].reopen other
|
119
119
|
end
|
120
120
|
|
121
|
-
#
|
121
|
+
# if one of the following is nil, bad things happen. this is deliberate.
|
122
|
+
# is it wise? that's an exercise left to the reader.
|
122
123
|
def close_all
|
123
|
-
self[:in]
|
124
|
-
self[:out]
|
125
|
-
self[:err]
|
124
|
+
self[:in].close
|
125
|
+
self[:out].close
|
126
|
+
self[:err].close
|
127
|
+
end
|
128
|
+
|
129
|
+
# These methods need to be implemented by those including this module
|
130
|
+
def returning; raise "Not Yet Implemented"; end
|
131
|
+
def wait; raise "Not Yet Implemented"; end
|
132
|
+
def reset; raise "Not Yet Implemented"; end
|
133
|
+
def run; raise "Not Yet Implemented"; end
|
134
|
+
|
135
|
+
# Generally the same as +run+, except for the ruby commands.
|
136
|
+
# they return real ruby that can be given back to the user.
|
137
|
+
def raw_run
|
138
|
+
run
|
126
139
|
end
|
127
|
-
|
128
|
-
# Methods to be done by those including this:
|
129
|
-
# wait
|
130
|
-
# reset
|
131
|
-
# run
|
132
|
-
# |(other) though this is easily done with a Pipe.new(self, other)
|
133
|
-
|
134
140
|
end
|
135
141
|
end
|
136
142
|
|
@@ -64,6 +64,8 @@ class Coolline
|
|
64
64
|
# return the first character you typed AFTER STDIN.getch got a chance
|
65
65
|
# to run. Ideally, with `read_char` it will read the first character that
|
66
66
|
# you typed regardless.
|
67
|
+
#
|
68
|
+
# Also, @history_moved appears to be a useless variable.
|
67
69
|
def readline(prompt = ">> ")
|
68
70
|
@prompt = prompt
|
69
71
|
|
@@ -31,5 +31,43 @@ class String
|
|
31
31
|
def /(other)
|
32
32
|
Chitin::Executable.new File.join(self, other.to_s)
|
33
33
|
end
|
34
|
+
|
35
|
+
def >>(other)
|
36
|
+
case other
|
37
|
+
when Chitin::FileObject
|
38
|
+
other.to_a.each do |fo|
|
39
|
+
next if fo.directory?
|
40
|
+
|
41
|
+
File.open(fo.to_s, 'a') {|f| f.puts self }
|
42
|
+
end
|
43
|
+
when String
|
44
|
+
File.open(other, 'a') {|f| f.puts self }
|
45
|
+
else
|
46
|
+
raise "Unknown piping type: #{other.class}"
|
47
|
+
end
|
48
|
+
|
49
|
+
other
|
50
|
+
end
|
51
|
+
|
52
|
+
def >(other)
|
53
|
+
case other
|
54
|
+
when Chitin::FileObject
|
55
|
+
other.to_a.each do |fo|
|
56
|
+
next if fo.directory?
|
57
|
+
|
58
|
+
File.open(fo.to_s, 'w') {|f| f.puts self }
|
59
|
+
end
|
60
|
+
when String
|
61
|
+
File.open(other, 'w') {|f| f.puts self }
|
62
|
+
else
|
63
|
+
raise "Unknown piping type: #{other.class}"
|
64
|
+
end
|
65
|
+
|
66
|
+
other
|
67
|
+
end
|
68
|
+
|
69
|
+
def |(other)
|
70
|
+
NULLIN > L { self } | other
|
71
|
+
end
|
34
72
|
end
|
35
73
|
|
data/lib/chitin/file.rb
CHANGED
@@ -61,6 +61,10 @@ module Chitin
|
|
61
61
|
def symlink?
|
62
62
|
false
|
63
63
|
end
|
64
|
+
|
65
|
+
def directory?
|
66
|
+
false
|
67
|
+
end
|
64
68
|
end
|
65
69
|
|
66
70
|
class FileObject < FSObject
|
@@ -132,6 +136,10 @@ module Chitin
|
|
132
136
|
def inspect
|
133
137
|
"#<Chitin::Directory #{path.inspect}>"
|
134
138
|
end
|
139
|
+
|
140
|
+
def directory?
|
141
|
+
true
|
142
|
+
end
|
135
143
|
end
|
136
144
|
end
|
137
145
|
|
@@ -144,6 +152,11 @@ module Kernel
|
|
144
152
|
alias_method :f, :F
|
145
153
|
alias_method :s, :S
|
146
154
|
|
147
|
-
|
155
|
+
# L for Lambda. Creates a proc as a RubyMethod
|
156
|
+
def L(&block)
|
157
|
+
Chitin::StringMethod.new :bottle, &block
|
158
|
+
end
|
159
|
+
|
160
|
+
NULLIN = NULLOUT = NULLERR = File.open(File::NULL, 'w+')
|
148
161
|
end
|
149
162
|
|
data/lib/chitin/sandbox.rb
CHANGED
data/lib/chitin/session.rb
CHANGED
@@ -17,7 +17,7 @@ module Chitin
|
|
17
17
|
@editor = Coolline.new do |c|
|
18
18
|
# Remove the default of '-' and add support for strings
|
19
19
|
# starting after parentheses.
|
20
|
-
c.word_boundaries = [' ', "\t", "(", ")"]
|
20
|
+
c.word_boundaries = [' ', "\t", "(", ")", '[', ']']
|
21
21
|
c.history_file = File.join ENV['HOME'], '.chitin_history'
|
22
22
|
|
23
23
|
# Make sure we don't kill the shell accidentally when we're trying to
|
@@ -41,6 +41,9 @@ module Chitin
|
|
41
41
|
# searching so we need it removed for now.
|
42
42
|
unquoted_line = ['"', '\''].include?(line[0, 1]) ? line[1..-1] : line
|
43
43
|
|
44
|
+
#options = Dir[unquoted_line + '*']
|
45
|
+
#options +=
|
46
|
+
|
44
47
|
Dir[unquoted_line + '*'].map do |w|
|
45
48
|
slash_it = File.directory?(w) and line[-1] != '/' and w[-1] != '/'
|
46
49
|
|
@@ -130,20 +133,16 @@ module Chitin
|
|
130
133
|
not returning_ruby? res
|
131
134
|
end
|
132
135
|
end
|
136
|
+
alias_method :all_shell?, :all_not_ruby?
|
133
137
|
|
134
138
|
def display(res)
|
135
139
|
# The reason that this is here instead of in #evaluate is that
|
136
140
|
# pipes could, in fact, have NO display output, but that isn't for
|
137
|
-
# #evaluate to decide
|
138
|
-
if
|
141
|
+
# #evaluate to decide: rather, it is for #display
|
142
|
+
if all_shell? res
|
139
143
|
res = [res] unless Array === res
|
140
144
|
|
141
145
|
res.each do |res|
|
142
|
-
# set up the inputs and outputs
|
143
|
-
res[:set_in, STDIN] unless res[:in]
|
144
|
-
res[:set_out, STDOUT] unless res[:out]
|
145
|
-
res[:set_err, STDOUT] unless res[:err]
|
146
|
-
|
147
146
|
res[:run]
|
148
147
|
res[:wait] unless res[:bg]
|
149
148
|
end
|
@@ -151,11 +150,6 @@ module Chitin
|
|
151
150
|
else # else it's a standard ruby type (or a pipe returning as such)
|
152
151
|
|
153
152
|
if Pipe === res || StringMethod === res
|
154
|
-
# set up the inputs and outputs
|
155
|
-
res[:set_in, STDIN] unless res[:in]
|
156
|
-
res[:set_out, STDOUT] unless res[:out]
|
157
|
-
res[:set_err, STDOUT] unless res[:err]
|
158
|
-
|
159
153
|
val = res[:raw_run]
|
160
154
|
else
|
161
155
|
val = res
|
@@ -184,5 +178,9 @@ module Chitin
|
|
184
178
|
def print(*args)
|
185
179
|
@out.print *args
|
186
180
|
end
|
181
|
+
|
182
|
+
def inspect
|
183
|
+
"#<Chitin::Session #{object_id}>"
|
184
|
+
end
|
187
185
|
end
|
188
186
|
end
|
data/lib/chitin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chitin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: wirble
|
@@ -73,6 +73,7 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- ANNOUNCEMENT
|
76
|
+
- LICENSE
|
76
77
|
- README
|
77
78
|
- TODO
|
78
79
|
- bin/chitin
|