Class: Mxrb::Runtime::Clipboard

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/runtime/clipboard.rb

Overview

Copies secrets through stdin so they never appear in the process list.

Constant Summary collapse

COMMANDS =
[
  ['wl-copy'], ['pbcopy'], ['xclip', '-selection', 'clipboard'],
  ['xsel', '--clipboard', '--input'], ['clip.exe']
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(path: ENV.fetch('PATH', ''), runner: nil) ⇒ Clipboard

Returns a new instance of Clipboard.



14
15
16
17
# File 'lib/mxrb/runtime/clipboard.rb', line 14

def initialize(path: ENV.fetch('PATH', ''), runner: nil)
  @path = path
  @runner = runner || method(:capture)
end

Instance Method Details

#copy(text) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mxrb/runtime/clipboard.rb', line 19

def copy(text)
  command = available_command
  unless command
    raise ToolchainError,
          'no clipboard command found; install wl-copy, pbcopy, xclip, xsel, or clip.exe'
  end

  _stdout, stderr, status = @runner.call(command, text.to_s)
  raise ToolchainError, "clipboard command failed: #{stderr}" unless status.success?

  command.first
end