xclip in a few lines of ruby

Update: I happened to check the source code of the ‘clipboard’ gem and it turns out that it depends on xclip. So the code below is just nonsense.

An xclip in a few lines of ruby

1
2
3
4
5
6
7
8
9
#!/usr/bin/env ruby

require 'clipboard'

if ARGV.empty?
Clipboard.copy ARGF.readlines.join("\n")
else
Clipboard.copy ARGV.join(' ')
end

###Use cases

1
2
3
4
5
#copy the html source of cosmicvent.com to clipboard
curl -s http://cosmicvent.com | xc

#copy date to clipboard
xc $(date)

I am currently working on LiveForm which makes setting up contact forms on your website a breeze.