Sha256: f9aee5494cad013471dde47b91939c0ea561d05ee8e35f21e0bd1df3897d2e26

Contents?: true

Size: 703 Bytes

Versions: 1

Compression:

Stored size: 703 Bytes

Contents

# frozen_string_literal: true

require 'os'

module Branch
  module Name
    module Clipable
      module_function

      def copy_to_clipboard(text)
        if OS.mac?
          copy_to_clipboard_macos text
          true
        elsif OS.windows?
          copy_to_clipboard_windows text
          true
        else
          false
        end
      end

      def copy_to_clipboard_macos(text)
        copy_to_clipboard_with(app: 'pbcopy', text: text)

      end

      def copy_to_clipboard_windows(text)
        copy_to_clipboard_with(app: 'clip', text: text)
      end

      def copy_to_clipboard_with(app:, text:)
        IO.popen(app, 'w') { |pipe| pipe.puts text }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
branch-name-2.1.0 lib/branch/name/clipable.rb