Skip to content

Instantly share code, notes, and snippets.

@RStankov
Created January 18, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RStankov/268d8ab4f0cf85cebf9aab971cb6f6f7 to your computer and use it in GitHub Desktop.
Save RStankov/268d8ab4f0cf85cebf9aab971cb6f6f7 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'open3'
module Clipboard
extend self
def paste
`pbpaste`
end
def copy(value)
run 'pbcopy', value
end
private
def run(cmd, data)
Open3.popen2(cmd) do |input, output, waiter_thread|
begin
input.write data
rescue Errno::EPIPE
end
input.close
waiter_thread.value
end
end
end
text = Clipboard.paste
text = text.gsub(/”\n\nExcerpt.*$/, '').gsub(/^“/, '')
Clipboard.copy(text)
print text
print "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment