Module: Clipboard::Linux

Extended by:
Linux
Included in:
Linux
Defined in:
lib/clipboard/linux.rb

Constant Summary collapse

CLIPBOARDS =
%w[clipboard primary secondary].freeze
WriteCommand =
'xclip'
ReadCommand =
'xclip -o'
ReadOutputStream =
false
Selection =
proc{ |x|
  "-selection #{x}"
}.freeze

Instance Method Summary collapse

Instance Method Details

#clearObject



40
41
42
# File 'lib/clipboard/linux.rb', line 40

def clear
  copy ''
end

#copy(data) ⇒ Object



44
45
46
47
48
49
# File 'lib/clipboard/linux.rb', line 44

def copy(data)
  CLIPBOARDS.each{ |which|
    Utils.popen "#{WriteCommand} #{Selection[which]}", data, ReadOutputStream
  }
  paste
end

#paste(which = nil) ⇒ Object



33
34
35
36
37
38
# File 'lib/clipboard/linux.rb', line 33

def paste(which = nil)
  if !which || !CLIPBOARDS.include?(which_normalized = which.to_s.downcase)
    which_normalized = CLIPBOARDS.first
  end
  `#{ReadCommand} #{Selection[which_normalized]} 2> /dev/null`
end