Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (unless (featurep 'simpleclip) (require 'simpleclip))
- (defun test-simpleclip ()
- (unwind-protect
- (let (retval)
- (condition-case ex
- (progn
- (simpleclip-set-contents "testsimpleclip!")
- (setq retval
- (string= "testsimpleclip!"
- (simpleclip-get-contents))))
- ('error
- (message (format "Please install %s to support clipboard from terminal."
- (cond
- (or (eq system-type 'gnu/linux)
- (eq system-type 'linux)
- (eq system-type 'usg-unix-v)
- (eq system-type 'berkeley-unix))
- "xsel or xclip")
- ((or (eq system-type 'cygwin) (eq system-type 'windows-nt))
- "cygutils-extra from Cygwin")
- (t
- "CLI clipboard tools"))))
- (setq retval nil)))
- retval)))
- (setq simpleclip-works (test-simpleclip))
- (defun my-gclip ()
- (cond
- (simpleclip-works
- (simpleclip-get-contents))
- ((eq system-type 'darwin)
- (with-output-to-string
- (with-current-buffer standard-output
- (call-process "/usr/bin/pbpaste" nil t nil "-Prefer" "txt"))))
- ((eq system-type 'cygwin)
- (with-output-to-string
- (with-current-buffer standard-output
- (call-process "getclip" nil t nil))))
- ((memq system-type '(gnu gnu/linux gnu/kfreebsd))
- (let* ((powershell-program (executable-find "powershell.exe")))
- (cond
- (powershell-program
- ;; PowerLine adds extra white space character at the end of text
- (string-trim-right
- (with-output-to-string
- (with-current-buffer standard-output
- (call-process powershell-program nil t nil "-command" "Get-Clipboard")))))
- (t
- (with-output-to-string
- (with-current-buffer standard-output
- (call-process "xsel" nil t nil "--clipboard" "--output")))))))))
- (defun paste-from-x-clipboard()
- "Paste from clipboard."
- (interactive "P")
- ;; paste after the cursor in evil normal state
- (when (and (functionp 'evil-normal-state-p)
- (functionp 'evil-move-cursor-back)
- (evil-normal-state-p)
- (not (eolp))
- (not (eobp)))
- (forward-char))
- (insert (my-gclip)))
Add Comment
Please, Sign In to add comment