Created
March 29, 2011 00:26
-
-
Save babney/891599 to your computer and use it in GitHub Desktop.
quick-and-dirty clipboard usage in ruby (OS X/Linux)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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