Sha256: 36f21af90dedb34f01c74df612d7213b9c7d910aa76930578dd6651eb5e8e91f
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
require 'open3' module Clipboard module Linux extend self CLIPBOARDS = %w[clipboard primary secondary].freeze # check which backend to use if system('which xclip >/dev/null 2>&1') WriteCommand = 'xclip'.freeze ReadCommand = 'xclip -o'.freeze Selection = proc{ |x| "-selection #{x}" }.freeze elsif system('which xsel >/dev/null 2>&1') WriteCommand = 'xsel -i'.freeze ReadCommand = 'xsel -o'.freeze Selection = { 'clipboard' => '-b', 'primary' => '-p', 'secondary' => '-s' }.freeze else raise Clipboard::ClipboardLoadError, "clipboard: Could not find required program xclip or xsel\n" \ "On debian/ubuntu, you can install it with: sudo apt-get install xclip" end def paste(which = nil) if !which || !CLIPBOARDS.include?(which.to_s.downcase) which = CLIPBOARDS.first end `#{ReadCommand} #{Selection[which.to_s.downcase]} 2> /dev/null` end def clear copy '' end def copy(data) CLIPBOARDS.each{ |which| Open3.popen3( "#{WriteCommand} #{Selection[which.to_s.downcase]}" ){ |input, _, _| input << data } } paste end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
clipboard-1.1.1 | lib/clipboard/linux.rb |