├── README ├── irbcp.gemspec ├── lib └── irbcp.rb └── Rakefile /README: -------------------------------------------------------------------------------- 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, linux and windows. 8 | 9 | SYNOPSIS 10 | 0) install the gem 11 | 12 | gem install irbcp 13 | 14 | 1) in your .irbrc do 15 | 16 | require 'rubygems' unless defined?(Gem) 17 | 18 | require 'irbcp' 19 | 20 | 2) now in irb you could do 21 | 22 | cp 'this data is copied to your clibboard from irb' 23 | 24 | 3) if you've copied something to your system clipboard you can simply do 25 | 26 | cp 27 | 28 | to paste it into irb 29 | 30 | NOTES 31 | - you can use the commands 'copy' and 'paste' if you love carpal tunnel 32 | 33 | - windows past support is via 34 | 35 | http://www.c3scripts.com/tutorials/msdos/paste.html#exe 36 | 37 | -------------------------------------------------------------------------------- /irbcp.gemspec: -------------------------------------------------------------------------------- 1 | ## irbcp.gemspec 2 | # 3 | 4 | Gem::Specification::new do |spec| 5 | spec.name = "irbcp" 6 | spec.version = "0.0.4" 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 | spec.add_dependency 'systemu' 23 | 24 | spec.extensions.push(*[]) 25 | 26 | spec.rubyforge_project = "codeforpeople" 27 | spec.author = "Ara T. Howard" 28 | spec.email = "ara.t.howard@gmail.com" 29 | spec.homepage = "https://github.com/ahoward/irbcp" 30 | end 31 | -------------------------------------------------------------------------------- /lib/irbcp.rb: -------------------------------------------------------------------------------- 1 | require 'systemu' 2 | 3 | module Irbcp 4 | Version = '0.0.4' 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 | ## Windows Server 2003 , Windows Vista , Windows 7. Anything else don t have and don t matter anymore :) 20 | # 21 | Copy = 'clip.exe' 22 | ## download paste.exe from http://www.c3scripts.com/tutorials/msdos/paste.html#exe 23 | # 24 | Paste = 'paste.exe' 25 | end 26 | 27 | def copy(*args) 28 | stdin = args.join 29 | systemu(Copy, :stdin => stdin) 30 | stdin 31 | end 32 | 33 | def paste(*args) 34 | stdout = '' 35 | systemu(Paste, :stdout => stdout) 36 | stdout 37 | end 38 | 39 | def cp(*args) 40 | args.size==0 ? paste(*args) : copy(*args) 41 | end 42 | 43 | extend(self) 44 | end 45 | 46 | IrbCp = Irbcp 47 | 48 | module Kernel 49 | private 50 | %w( copy paste cp ).each do |method| 51 | module_eval <<-__ 52 | def #{ method }(*args, &block) 53 | Irbcp.#{ method }(*args, &block) 54 | end 55 | __ 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 | spec.add_dependency 'systemu' 130 | 131 | spec.extensions.push(*#{ extensions.inspect }) 132 | 133 | spec.rubyforge_project = #{ This.rubyforge_project.inspect } 134 | spec.author = #{ This.author.inspect } 135 | spec.email = #{ This.email.inspect } 136 | spec.homepage = #{ This.homepage.inspect } 137 | end 138 | __ 139 | } 140 | end 141 | 142 | Fu.mkdir_p(This.pkgdir) 143 | gemspec = "#{ lib }.gemspec" 144 | open(gemspec, "w"){|fd| fd.puts(template)} 145 | This.gemspec = gemspec 146 | end 147 | 148 | task :gem => [:clean, :gemspec] do 149 | Fu.mkdir_p(This.pkgdir) 150 | before = Dir['*.gem'] 151 | cmd = "gem build #{ This.gemspec }" 152 | `#{ cmd }` 153 | after = Dir['*.gem'] 154 | gem = ((after - before).first || after.first) or abort('no gem!') 155 | Fu.mv(gem, This.pkgdir) 156 | This.gem = File.join(This.pkgdir, File.basename(gem)) 157 | end 158 | 159 | task :readme do 160 | samples = '' 161 | prompt = '~ > ' 162 | lib = This.lib 163 | version = This.version 164 | 165 | Dir['sample*/*'].sort.each do |sample| 166 | samples << "\n" << " <========< #{ sample } >========>" << "\n\n" 167 | 168 | cmd = "cat #{ sample }" 169 | samples << Util.indent(prompt + cmd, 2) << "\n\n" 170 | samples << Util.indent(`#{ cmd }`, 4) << "\n" 171 | 172 | cmd = "ruby #{ sample }" 173 | samples << Util.indent(prompt + cmd, 2) << "\n\n" 174 | 175 | cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'" 176 | samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n" 177 | end 178 | 179 | template = 180 | if test(?e, 'readme.erb') 181 | Template{ IO.read('readme.erb') } 182 | else 183 | Template { 184 | <<-__ 185 | NAME 186 | #{ lib } 187 | 188 | DESCRIPTION 189 | 190 | INSTALL 191 | gem install #{ lib } 192 | 193 | SAMPLES 194 | #{ samples } 195 | __ 196 | } 197 | end 198 | 199 | open("README", "w"){|fd| fd.puts template} 200 | end 201 | 202 | 203 | task :clean do 204 | Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)} 205 | end 206 | 207 | 208 | task :release => [:clean, :gemspec, :gem] do 209 | gems = Dir[File.join(This.pkgdir, '*.gem')].flatten 210 | raise "which one? : #{ gems.inspect }" if gems.size > 1 211 | raise "no gems?" if gems.size < 1 212 | 213 | cmd = "gem push #{ This.gem }" 214 | puts cmd 215 | puts 216 | system(cmd) 217 | abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero? 218 | 219 | cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }" 220 | puts cmd 221 | puts 222 | system(cmd) 223 | abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero? 224 | end 225 | 226 | 227 | 228 | 229 | 230 | BEGIN { 231 | # support for this rakefile 232 | # 233 | $VERBOSE = nil 234 | 235 | require 'ostruct' 236 | require 'erb' 237 | require 'fileutils' 238 | require 'rbconfig' 239 | require 'pp' 240 | 241 | # fu shortcut 242 | # 243 | Fu = FileUtils 244 | 245 | # cache a bunch of stuff about this rakefile/environment 246 | # 247 | This = OpenStruct.new 248 | 249 | This.file = File.expand_path(__FILE__) 250 | This.dir = File.dirname(This.file) 251 | This.pkgdir = File.join(This.dir, 'pkg') 252 | 253 | # grok lib 254 | # 255 | lib = ENV['LIB'] 256 | unless lib 257 | lib = File.basename(Dir.pwd).sub(/[-].*$/, '') 258 | end 259 | This.lib = lib 260 | 261 | # grok version 262 | # 263 | version = ENV['VERSION'] 264 | unless version 265 | require "./lib/#{ This.lib }" 266 | This.name = lib.capitalize 267 | This.object = eval(This.name) 268 | version = This.object.send(:version) 269 | end 270 | This.version = version 271 | 272 | # we need to know the name of the lib an it's version 273 | # 274 | abort('no lib') unless This.lib 275 | abort('no version') unless This.version 276 | 277 | # discover full path to this ruby executable 278 | # 279 | c = Config::CONFIG 280 | bindir = c["bindir"] || c['BINDIR'] 281 | ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby' 282 | ruby_ext = c['EXEEXT'] || '' 283 | ruby = File.join(bindir, (ruby_install_name + ruby_ext)) 284 | This.ruby = ruby 285 | 286 | # some utils 287 | # 288 | module Util 289 | def indent(s, n = 2) 290 | s = unindent(s) 291 | ws = ' ' * n 292 | s.gsub(%r/^/, ws) 293 | end 294 | 295 | def unindent(s) 296 | indent = nil 297 | s.each_line do |line| 298 | next if line =~ %r/^\s*$/ 299 | indent = line[%r/^\s*/] and break 300 | end 301 | indent ? s.gsub(%r/^#{ indent }/, "") : s 302 | end 303 | extend self 304 | end 305 | 306 | # template support 307 | # 308 | class Template 309 | def initialize(&block) 310 | @block = block 311 | @template = block.call.to_s 312 | end 313 | def expand(b=nil) 314 | ERB.new(Util.unindent(@template)).result((b||@block).binding) 315 | end 316 | alias_method 'to_s', 'expand' 317 | end 318 | def Template(*args, &block) Template.new(*args, &block) end 319 | 320 | # colored console output support 321 | # 322 | This.ansi = { 323 | :clear => "\e[0m", 324 | :reset => "\e[0m", 325 | :erase_line => "\e[K", 326 | :erase_char => "\e[P", 327 | :bold => "\e[1m", 328 | :dark => "\e[2m", 329 | :underline => "\e[4m", 330 | :underscore => "\e[4m", 331 | :blink => "\e[5m", 332 | :reverse => "\e[7m", 333 | :concealed => "\e[8m", 334 | :black => "\e[30m", 335 | :red => "\e[31m", 336 | :green => "\e[32m", 337 | :yellow => "\e[33m", 338 | :blue => "\e[34m", 339 | :magenta => "\e[35m", 340 | :cyan => "\e[36m", 341 | :white => "\e[37m", 342 | :on_black => "\e[40m", 343 | :on_red => "\e[41m", 344 | :on_green => "\e[42m", 345 | :on_yellow => "\e[43m", 346 | :on_blue => "\e[44m", 347 | :on_magenta => "\e[45m", 348 | :on_cyan => "\e[46m", 349 | :on_white => "\e[47m" 350 | } 351 | def say(phrase, *args) 352 | options = args.last.is_a?(Hash) ? args.pop : {} 353 | options[:color] = args.shift.to_s.to_sym unless args.empty? 354 | keys = options.keys 355 | keys.each{|key| options[key.to_s.to_sym] = options.delete(key)} 356 | 357 | color = options[:color] 358 | bold = options.has_key?(:bold) 359 | 360 | parts = [phrase] 361 | parts.unshift(This.ansi[color]) if color 362 | parts.unshift(This.ansi[:bold]) if bold 363 | parts.push(This.ansi[:clear]) if parts.size > 1 364 | 365 | method = options[:method] || :puts 366 | 367 | Kernel.send(method, parts.join) 368 | end 369 | 370 | # always run out of the project dir 371 | # 372 | Dir.chdir(This.dir) 373 | } 374 | --------------------------------------------------------------------------------