-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path15-detect-clipboard.zsh
113 lines (112 loc) · 2.4 KB
/
15-detect-clipboard.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/env/bin zsh
detect-clipboard () {
# emulate -L zsh - use it with other shells
if [[ "${OSTYPE}" == darwin* ]] && (( ${+commands[pbcopy]} )) && (( ${+commands[pbpaste]} ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | pbcopy
}
clippaste () {
pbpaste
}
elif [[ "${OSTYPE}" == (cygwin|msys)* ]]
then
clipcopy () {
cat "${1:-/dev/stdin}" > /dev/clipboard
}
clippaste () {
cat /dev/clipboard
}
elif (( $+commands[clip.exe] )) && (( $+commands[powershell.exe] ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | clip.exe
}
clippaste () {
powershell.exe -noprofile -command Get-Clipboard
}
elif [ -n "${WAYLAND_DISPLAY:-}" ] && (( ${+commands[wl-copy]} )) && (( ${+commands[wl-paste]} ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | wl-copy &> /dev/null &|
}
clippaste () {
wl-paste --no-newline
}
elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xsel]} ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | xsel --clipboard --input
}
clippaste () {
xsel --clipboard --output
}
elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xclip]} ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | xclip -selection clipboard -in &> /dev/null &|
}
clippaste () {
xclip -out -selection clipboard
}
elif (( ${+commands[lemonade]} ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | lemonade copy
}
clippaste () {
lemonade paste
}
elif (( ${+commands[doitclient]} ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | doitclient wclip
}
clippaste () {
doitclient wclip -r
}
elif (( ${+commands[win32yank]} ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | win32yank -i
}
clippaste () {
win32yank -o
}
elif [[ $OSTYPE == linux-android* ]] && (( $+commands[termux-clipboard-set] ))
then
clipcopy () {
cat "${1:-/dev/stdin}" | termux-clipboard-set
}
clippaste () {
termux-clipboard-get
}
elif [ -n "${TMUX:-}" ] && (( ${+commands[tmux]} ))
then
clipcopy () {
tmux load-buffer "${1:--}"
}
clippaste () {
tmux save-buffer -
}
else
_retry_clipboard_detection_or_fail () {
local clipcmd="${1}"
shift
if detect-clipboard
then
"${clipcmd}" "$@"
else
print "${clipcmd}: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
return 1
fi
}
clipcopy () {
_retry_clipboard_detection_or_fail clipcopy "$@"
}
clippaste () {
_retry_clipboard_detection_or_fail clippaste "$@"
}
return 1
fi
}