Diff
1diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh
2index 512a5a2489c792c379ed12164b5558f626187041..17d8d1aaf1a95fb2a3b5d26a6fc7bb74f6a5313e 100644
3--- a/lib/clipboard.zsh
4+++ b/lib/clipboard.zsh
5@@ -3,10 +3,23 @@
6 # This file has support for doing system clipboard copy and paste operations
7 # from the command line in a generic cross-platform fashion.
8 #
9-# On OS X and Windows, the main system clipboard or "pasteboard" is used. On other
10-# Unix-like OSes, this considers the X Windows CLIPBOARD selection to be the
11-# "system clipboard", and the X Windows `xclip` command must be installed.
12-
13+# This is uses essentially the same heuristic as neovim, with the additional
14+# special support for Cygwin.
15+# See: https://github.com/neovim/neovim/blob/e682d799fa3cf2e80a02d00c6ea874599d58f0e7/runtime/autoload/provider/clipboard.vim#L55-L121
16+#
17+# - pbcopy, pbpaste (macOS)
18+# - cygwin (Windows running Cygwin)
19+# - wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
20+# - xclip (if $DISPLAY is set)
21+# - xsel (if $DISPLAY is set)
22+# - lemonade (for SSH) https://github.com/pocke/lemonade
23+# - doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
24+# - win32yank (Windows)
25+# - tmux (if $TMUX is set)
26+#
27+# Defines two functions, clipcopy and clippaste, based on the detected platform.
28+##
29+#
30 # clipcopy - Copy data to clipboard
31 #
32 # Usage:
33@@ -15,7 +28,6 @@
34 #
35 # clipcopy <file> - copies a file's contents to clipboard
36 #
37-#
38 ##
39 #
40 # clippaste - "Paste" data from clipboard to stdout
41@@ -39,18 +51,33 @@
42 function detect-clipboard() {
43 emulate -L zsh
44
45- if [[ $OSTYPE == darwin* ]]; then
46+ if [[ "${OSTYPE}" == darwin* ]] && (( ${+commands[pbcopy]} )) && (( ${+commands[pbpaste]} )); then
47 function clipcopy() { pbcopy < "${1:-/dev/stdin}"; }
48 function clippaste() { pbpaste; }
49- elif [[ $OSTYPE == cygwin* ]]; then
50+ elif [[ "${OSTYPE}" == cygwin* ]]; then
51 function clipcopy() { cat "${1:-/dev/stdin}" > /dev/clipboard; }
52 function clippaste() { cat /dev/clipboard; }
53- elif (( $+commands[xclip] )); then
54+ elif [ -n "${WAYLAND_DISPLAY:-}" ] && (( ${+commands[wl-copy]} )) && (( ${+commands[wl-paste]} )); then
55+ function clipcopy() { wl-copy < "${1:-/dev/stdin}"; }
56+ function clippaste() { wl-paste; }
57+ elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xclip]} )); then
58 function clipcopy() { xclip -in -selection clipboard < "${1:-/dev/stdin}"; }
59 function clippaste() { xclip -out -selection clipboard; }
60- elif (( $+commands[xsel] )); then
61- function clipcopy() { xsel --clipboard --input < "${1:-/dev/stdin}"; }
62+ elif [ -n "${DISPLAY:-}" ] && $(( ${+commands[xsel]} )); then
63+ function clipcopy() { xsel --clipboard --input < "${1:-/dev/stdin}"; }
64 function clippaste() { xsel --clipboard --output; }
65+ elif (( ${+commands[lemonade]} )); then
66+ function clipcopy() { lemonade copy < "${1:-/dev/stdin}"; }
67+ function clippaste() { lemonade paste; }
68+ elif (( ${+commands[doitclient]} )); then
69+ function clipcopy() { doitclient wclip < "${1:-/dev/stdin}"; }
70+ function clippaste() { doitclient wclip -r; }
71+ elif (( ${+commands[win32yank]} )); then
72+ function clipcopy() { win32yank -i < "${1:-/dev/stdin}"; }
73+ function clippaste() { win32yank -o; }
74+ elif [ -n "${TMUX:-}" ] && (( ${+commands[tmux]} )); then
75+ function clipcopy() { tmux load-buffer "${1:-/dev/stdin}"; }
76+ function clippaste() { tmux save-buffer -; }
77 else
78 function _retry_clipboard_detection_or_fail() {
79 local clipcmd="${1}"; shift