Module: Commiti::Clipboard
- Defined in:
- lib/services/helpers/clipboard.rb
Class Method Summary collapse
Class Method Details
.command_exists?(cmd) ⇒ Boolean
40 41 42 |
# File 'lib/services/helpers/clipboard.rb', line 40 def self.command_exists?(cmd) system('which', cmd, out: File::NULL, err: File::NULL) end |
.copy(text) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/services/helpers/clipboard.rb', line 5 def self.copy(text) case platform when :mac IO.popen('pbcopy', 'w') { |io| io.write(text) } true when :linux if command_exists?('xclip') IO.popen('xclip -selection clipboard', 'w') { |io| io.write(text) } true elsif command_exists?('xsel') IO.popen('xsel --clipboard --input', 'w') { |io| io.write(text) } true else false # no clipboard tool found end when :windows IO.popen('clip', 'w') { |io| io.write(text) } true else false end end |
.platform ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/services/helpers/clipboard.rb', line 28 def self.platform if RUBY_PLATFORM.include?('darwin') :mac elsif RUBY_PLATFORM.include?('linux') :linux elsif RUBY_PLATFORM.include?('mingw') || RUBY_PLATFORM.include?('mswin') :windows else :unknown end end |