Skip to content

Instantly share code, notes, and snippets.

@babney
Created March 29, 2011 00:26
Show Gist options
  • Save babney/891599 to your computer and use it in GitHub Desktop.
Save babney/891599 to your computer and use it in GitHub Desktop.
quick-and-dirty clipboard usage in ruby (OS X/Linux)
class Object
unless method_defined?(:clip) || !self.respond_to?(:to_s)
def clip # won't work in windows, but I doubt it'll ever be an issue...
if RUBY_PLATFORM.downcase.include?("darwin")
IO.popen('pbcopy', 'w+') do |clipboard|
clipboard.write(self.to_s)
end
elsif RUBY_PLATFORM.downcase.include?("linux") #requires xsel to be installed
IO.popen('xsel --clipboard --input', 'r+') do |clipboard|
clipboard.puts self.to_s
end
end
self
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment