irbcp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +35 -0
  2. data/Rakefile +372 -0
  3. data/irbcp.gemspec +29 -0
  4. data/lib/irbcp.rb +52 -0
  5. metadata +70 -0
data/README ADDED
@@ -0,0 +1,35 @@
1
+ NAME
2
+ irbcp
3
+
4
+ DESCRIPTION
5
+ irbcp gives access to your system's clipboard (copy and paste) from irb
6
+
7
+ it works on osx and linux
8
+
9
+ SYNOPSIS
10
+
11
+ 0) install the gem
12
+
13
+ gem install irbcp
14
+
15
+ 1) in your .irbrc do
16
+
17
+ require 'rubygems' unless defined?(Gem)
18
+
19
+ require 'irbcp'
20
+
21
+ 2) now in irb you could do
22
+
23
+ cp 'this data is copied to your clibboard from irb'
24
+
25
+ 3) if you've copied something to your system clipboard you can simply do
26
+
27
+ cp
28
+
29
+ to paste it into irb
30
+
31
+ NOTE:
32
+ you can use the commands 'copy' and 'paste' if you love carpal tunnel
33
+
34
+ WINDOWS
35
+ send a patch!
data/Rakefile ADDED
@@ -0,0 +1,372 @@
1
+ This.rubyforge_project = 'codeforpeople'
2
+ This.author = "Ara T. Howard"
3
+ This.email = "ara.t.howard@gmail.com"
4
+ This.homepage = "https://github.com/ahoward/#{ This.lib }"
5
+
6
+
7
+ task :default do
8
+ puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
9
+ end
10
+
11
+ task :test do
12
+ run_tests!
13
+ end
14
+
15
+ namespace :test do
16
+ task(:unit){ run_tests!(:unit) }
17
+ task(:functional){ run_tests!(:functional) }
18
+ task(:integration){ run_tests!(:integration) }
19
+ end
20
+
21
+ def run_tests!(which = nil)
22
+ which ||= '**'
23
+ test_dir = File.join(This.dir, "test")
24
+ test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
25
+ test_rbs = Dir.glob(test_glob).sort
26
+
27
+ div = ('=' * 119)
28
+ line = ('-' * 119)
29
+ helper = "-r ./test/helper.rb" if test(?e, "./test/helper.rb")
30
+
31
+ test_rbs.each_with_index do |test_rb, index|
32
+ testno = index + 1
33
+ command = "#{ This.ruby } -I ./lib -I ./test/lib #{ helper } #{ test_rb }"
34
+
35
+ puts
36
+ say(div, :color => :cyan, :bold => true)
37
+ say("@#{ testno } => ", :bold => true, :method => :print)
38
+ say(command, :color => :cyan, :bold => true)
39
+ say(line, :color => :cyan, :bold => true)
40
+
41
+ system(command)
42
+
43
+ say(line, :color => :cyan, :bold => true)
44
+
45
+ status = $?.exitstatus
46
+
47
+ if status.zero?
48
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
49
+ say("SUCCESS", :color => :green, :bold => true)
50
+ else
51
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
52
+ say("FAILURE", :color => :red, :bold => true)
53
+ end
54
+ say(line, :color => :cyan, :bold => true)
55
+
56
+ exit(status) unless status.zero?
57
+ end
58
+ end
59
+
60
+
61
+ task :gemspec do
62
+ ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
63
+ ignore_directories = ['pkg']
64
+ ignore_files = ['test/log']
65
+
66
+ shiteless =
67
+ lambda do |list|
68
+ list.delete_if do |entry|
69
+ next unless test(?e, entry)
70
+ extension = File.basename(entry).split(%r/[.]/).last
71
+ ignore_extensions.any?{|ext| ext === extension}
72
+ end
73
+ list.delete_if do |entry|
74
+ next unless test(?d, entry)
75
+ dirname = File.expand_path(entry)
76
+ ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
77
+ end
78
+ list.delete_if do |entry|
79
+ next unless test(?f, entry)
80
+ filename = File.expand_path(entry)
81
+ ignore_files.any?{|file| File.expand_path(file) == filename}
82
+ end
83
+ end
84
+
85
+ lib = This.lib
86
+ object = This.object
87
+ version = This.version
88
+ files = shiteless[Dir::glob("**/**")]
89
+ executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
90
+ #has_rdoc = true #File.exist?('doc')
91
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
92
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
93
+ description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
94
+
95
+ if This.extensions.nil?
96
+ This.extensions = []
97
+ extensions = This.extensions
98
+ %w( Makefile configure extconf.rb ).each do |ext|
99
+ extensions << ext if File.exists?(ext)
100
+ end
101
+ end
102
+ extensions = [extensions].flatten.compact
103
+
104
+ template =
105
+ if test(?e, 'gemspec.erb')
106
+ Template{ IO.read('gemspec.erb') }
107
+ else
108
+ Template {
109
+ <<-__
110
+ ## #{ lib }.gemspec
111
+ #
112
+
113
+ Gem::Specification::new do |spec|
114
+ spec.name = #{ lib.inspect }
115
+ spec.version = #{ version.inspect }
116
+ spec.platform = Gem::Platform::RUBY
117
+ spec.summary = #{ lib.inspect }
118
+ spec.description = #{ description.inspect }
119
+
120
+ spec.files =\n#{ files.sort.pretty_inspect }
121
+ spec.executables = #{ executables.inspect }
122
+
123
+ spec.require_path = "lib"
124
+
125
+ spec.test_files = #{ test_files.inspect }
126
+
127
+ ### spec.add_dependency 'lib', '>= version'
128
+ #### spec.add_dependency 'map'
129
+
130
+ spec.extensions.push(*#{ extensions.inspect })
131
+
132
+ spec.rubyforge_project = #{ This.rubyforge_project.inspect }
133
+ spec.author = #{ This.author.inspect }
134
+ spec.email = #{ This.email.inspect }
135
+ spec.homepage = #{ This.homepage.inspect }
136
+ end
137
+ __
138
+ }
139
+ end
140
+
141
+ Fu.mkdir_p(This.pkgdir)
142
+ gemspec = "#{ lib }.gemspec"
143
+ open(gemspec, "w"){|fd| fd.puts(template)}
144
+ This.gemspec = gemspec
145
+ end
146
+
147
+ task :gem => [:clean, :gemspec] do
148
+ Fu.mkdir_p(This.pkgdir)
149
+ before = Dir['*.gem']
150
+ cmd = "gem build #{ This.gemspec }"
151
+ `#{ cmd }`
152
+ after = Dir['*.gem']
153
+ gem = ((after - before).first || after.first) or abort('no gem!')
154
+ Fu.mv(gem, This.pkgdir)
155
+ This.gem = File.join(This.pkgdir, File.basename(gem))
156
+ end
157
+
158
+ task :readme do
159
+ samples = ''
160
+ prompt = '~ > '
161
+ lib = This.lib
162
+ version = This.version
163
+
164
+ Dir['sample*/*'].sort.each do |sample|
165
+ samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
166
+
167
+ cmd = "cat #{ sample }"
168
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
169
+ samples << Util.indent(`#{ cmd }`, 4) << "\n"
170
+
171
+ cmd = "ruby #{ sample }"
172
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
173
+
174
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
175
+ samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
176
+ end
177
+
178
+ template =
179
+ if test(?e, 'readme.erb')
180
+ Template{ IO.read('readme.erb') }
181
+ else
182
+ Template {
183
+ <<-__
184
+ NAME
185
+ #{ lib }
186
+
187
+ DESCRIPTION
188
+
189
+ INSTALL
190
+ gem install #{ lib }
191
+
192
+ SAMPLES
193
+ #{ samples }
194
+ __
195
+ }
196
+ end
197
+
198
+ open("README", "w"){|fd| fd.puts template}
199
+ end
200
+
201
+
202
+ task :clean do
203
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
204
+ end
205
+
206
+
207
+ task :release => [:clean, :gemspec, :gem] do
208
+ gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
209
+ raise "which one? : #{ gems.inspect }" if gems.size > 1
210
+ raise "no gems?" if gems.size < 1
211
+
212
+ cmd = "gem push #{ This.gem }"
213
+ puts cmd
214
+ puts
215
+ system(cmd)
216
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
217
+
218
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
219
+ puts cmd
220
+ puts
221
+ system(cmd)
222
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
223
+ end
224
+
225
+
226
+
227
+
228
+
229
+ BEGIN {
230
+ # support for this rakefile
231
+ #
232
+ $VERBOSE = nil
233
+
234
+ require 'ostruct'
235
+ require 'erb'
236
+ require 'fileutils'
237
+ require 'rbconfig'
238
+ require 'pp'
239
+
240
+ # fu shortcut
241
+ #
242
+ Fu = FileUtils
243
+
244
+ # cache a bunch of stuff about this rakefile/environment
245
+ #
246
+ This = OpenStruct.new
247
+
248
+ This.file = File.expand_path(__FILE__)
249
+ This.dir = File.dirname(This.file)
250
+ This.pkgdir = File.join(This.dir, 'pkg')
251
+
252
+ # grok lib
253
+ #
254
+ lib = ENV['LIB']
255
+ unless lib
256
+ lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
257
+ end
258
+ This.lib = lib
259
+
260
+ # grok version
261
+ #
262
+ version = ENV['VERSION']
263
+ unless version
264
+ require "./lib/#{ This.lib }"
265
+ This.name = lib.capitalize
266
+ This.object = eval(This.name)
267
+ version = This.object.send(:version)
268
+ end
269
+ This.version = version
270
+
271
+ # we need to know the name of the lib an it's version
272
+ #
273
+ abort('no lib') unless This.lib
274
+ abort('no version') unless This.version
275
+
276
+ # discover full path to this ruby executable
277
+ #
278
+ c = Config::CONFIG
279
+ bindir = c["bindir"] || c['BINDIR']
280
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
281
+ ruby_ext = c['EXEEXT'] || ''
282
+ ruby = File.join(bindir, (ruby_install_name + ruby_ext))
283
+ This.ruby = ruby
284
+
285
+ # some utils
286
+ #
287
+ module Util
288
+ def indent(s, n = 2)
289
+ s = unindent(s)
290
+ ws = ' ' * n
291
+ s.gsub(%r/^/, ws)
292
+ end
293
+
294
+ def unindent(s)
295
+ indent = nil
296
+ s.each_line do |line|
297
+ next if line =~ %r/^\s*$/
298
+ indent = line[%r/^\s*/] and break
299
+ end
300
+ indent ? s.gsub(%r/^#{ indent }/, "") : s
301
+ end
302
+ extend self
303
+ end
304
+
305
+ # template support
306
+ #
307
+ class Template
308
+ def initialize(&block)
309
+ @block = block
310
+ @template = block.call.to_s
311
+ end
312
+ def expand(b=nil)
313
+ ERB.new(Util.unindent(@template)).result((b||@block).binding)
314
+ end
315
+ alias_method 'to_s', 'expand'
316
+ end
317
+ def Template(*args, &block) Template.new(*args, &block) end
318
+
319
+ # colored console output support
320
+ #
321
+ This.ansi = {
322
+ :clear => "\e[0m",
323
+ :reset => "\e[0m",
324
+ :erase_line => "\e[K",
325
+ :erase_char => "\e[P",
326
+ :bold => "\e[1m",
327
+ :dark => "\e[2m",
328
+ :underline => "\e[4m",
329
+ :underscore => "\e[4m",
330
+ :blink => "\e[5m",
331
+ :reverse => "\e[7m",
332
+ :concealed => "\e[8m",
333
+ :black => "\e[30m",
334
+ :red => "\e[31m",
335
+ :green => "\e[32m",
336
+ :yellow => "\e[33m",
337
+ :blue => "\e[34m",
338
+ :magenta => "\e[35m",
339
+ :cyan => "\e[36m",
340
+ :white => "\e[37m",
341
+ :on_black => "\e[40m",
342
+ :on_red => "\e[41m",
343
+ :on_green => "\e[42m",
344
+ :on_yellow => "\e[43m",
345
+ :on_blue => "\e[44m",
346
+ :on_magenta => "\e[45m",
347
+ :on_cyan => "\e[46m",
348
+ :on_white => "\e[47m"
349
+ }
350
+ def say(phrase, *args)
351
+ options = args.last.is_a?(Hash) ? args.pop : {}
352
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
353
+ keys = options.keys
354
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
355
+
356
+ color = options[:color]
357
+ bold = options.has_key?(:bold)
358
+
359
+ parts = [phrase]
360
+ parts.unshift(This.ansi[color]) if color
361
+ parts.unshift(This.ansi[:bold]) if bold
362
+ parts.push(This.ansi[:clear]) if parts.size > 1
363
+
364
+ method = options[:method] || :puts
365
+
366
+ Kernel.send(method, parts.join)
367
+ end
368
+
369
+ # always run out of the project dir
370
+ #
371
+ Dir.chdir(This.dir)
372
+ }
data/irbcp.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ ## irbcp.gemspec
2
+ #
3
+
4
+ Gem::Specification::new do |spec|
5
+ spec.name = "irbcp"
6
+ spec.version = "0.0.1"
7
+ spec.platform = Gem::Platform::RUBY
8
+ spec.summary = "irbcp"
9
+ spec.description = "description: irbcp kicks the ass"
10
+
11
+ spec.files =
12
+ ["README", "Rakefile", "irbcp.gemspec", "irbcp.rb", "lib", "lib/irbcp.rb"]
13
+
14
+ spec.executables = []
15
+
16
+ spec.require_path = "lib"
17
+
18
+ spec.test_files = nil
19
+
20
+ ### spec.add_dependency 'lib', '>= version'
21
+ #### spec.add_dependency 'map'
22
+
23
+ spec.extensions.push(*[])
24
+
25
+ spec.rubyforge_project = "codeforpeople"
26
+ spec.author = "Ara T. Howard"
27
+ spec.email = "ara.t.howard@gmail.com"
28
+ spec.homepage = "https://github.com/ahoward/irbcp"
29
+ end
data/lib/irbcp.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'systemu'
2
+
3
+ module Irbcp
4
+ Version = '0.0.1'
5
+
6
+ def Irbcp.version() Irbcp::Version end
7
+
8
+
9
+ case RUBY_PLATFORM
10
+ when /darwin/
11
+ Copy = 'pbcopy'
12
+ Paste = 'pbpaste'
13
+
14
+ when /linux/
15
+ Copy = 'xsel –clipboard –input'
16
+ Paste = 'xsel –clipboard –output'
17
+
18
+ when /windoze/
19
+ raise 'fail!' # TODO !
20
+ end
21
+
22
+ def copy(*args)
23
+ stdin = args.join
24
+ systemu(Copy, :stdin => stdin)
25
+ stdin
26
+ end
27
+
28
+ def paste(*args)
29
+ stdout = ''
30
+ systemu(Paste, :stdout => stdout)
31
+ stdout
32
+ end
33
+
34
+ def cp(*args)
35
+ args.size==0 ? paste(*args) : copy(*args)
36
+ end
37
+
38
+ extend(self)
39
+ end
40
+
41
+ IrbCp = Irbcp
42
+
43
+ module Kernel
44
+ private
45
+ %w( copy paste cp ).each do |method|
46
+ module_eval <<-__
47
+ def #{ method }(*args, &block)
48
+ Irbcp.#{ method }(*args, &block)
49
+ end
50
+ __
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irbcp
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ara T. Howard
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-02 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "description: irbcp kicks the ass"
23
+ email: ara.t.howard@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README
32
+ - Rakefile
33
+ - irbcp.gemspec
34
+ - lib/irbcp.rb
35
+ has_rdoc: true
36
+ homepage: https://github.com/ahoward/irbcp
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !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
+ requirements: []
63
+
64
+ rubyforge_project: codeforpeople
65
+ rubygems_version: 1.4.2
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: irbcp
69
+ test_files: []
70
+