Skip to content

Instantly share code, notes, and snippets.

@mecab
Last active July 22, 2017 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mecab/2ea01bf0059c40795fae2becb681d059 to your computer and use it in GitHub Desktop.
Save mecab/2ea01bf0059c40795fae2becb681d059 to your computer and use it in GitHub Desktop.
Send region to the clipboard via the xterm clipboard integration (PASTE64/OSC52)
(defun send-region-to-clipboard (START END)
;; Place https://github.com/skaji/remote-pbcopy-iterm2/blob/master/pbcopy as `cpbcopy`
(interactive "r")
(let ((infile (make-temp-file "send-region-to-clipboard")))
(write-region (buffer-substring (region-beginning) (region-end))
nil
infile
nil
'nomsg)
(with-temp-buffer
(call-process "cpbcopy" infile t)
(send-string-to-terminal (buffer-substring-no-properties
(point-min) (point-max))))
(delete-file infile)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment