I'm always looking for little ways to speed up my development. I'm a big fan of Mac OS X's pbcopy
& pbpaste
commands. I've quite often found myself wanting to use them in irb
. Today I knocked up a simple addition to your .irbrc
to access the commands from ruby.
module Clipboard
def pbcopy(data)
IO.popen('pbcopy', 'w') {|io| io.write(data)}
end
def pbpaste
IO.popen('pbpaste', 'r').read
end
end
include Clipboard
You can use it as follows:
>> pbcopy "Test"
=> 4
>> pbpaste
=> "Test"
I've added the code to a Gist. Use it, fork it, modify it.