-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclipboard.plugin.zsh
53 lines (47 loc) · 1.17 KB
/
clipboard.plugin.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
#!/usr/bin/env bash
__clipboard_cutbuffer() {
zle .$WIDGET
if [[ "$OSTYPE" == darwin* ]]; then
echo $CUTBUFFER | pbcopy
elif [[ "$OSTYPE" == cygwin* ]]; then
echo $CUTBUFFER | tee > /dev/clipboard
elif (( $+commands[xclip] )); then
echo $CUTBUFFER | xclip -selection clipboard
elif (( $+commands[xsel] )); then
echo $CUTBUFFER | xsel --clipboard --input
fi
}
zle_cut_widgets=(
vi-backward-delete-char
vi-change
vi-change-eol
vi-change-whole-line
vi-delete
vi-delete-char
vi-kill-eol
vi-substitute
vi-yank
vi-yank-eol
)
for widget in $zle_cut_widgets; do
zle -N $widget __clipboard_cutbuffer
done
__clipboard_putbuffer() {
if [[ "$OSTYPE" == darwin* ]]; then
zle copy-region-as-kill "$(pbpaste)"
elif [[ "$OSTYPE" == cygwin* ]]; then
zle copy-region-as-kill "$(cat /dev/clipboard)"
elif (( $+commands[xclip] )); then
zle copy-region-as-kill "$(xclip -o -selection clipboard)"
elif (( $+commands[xsel] )); then
zle copy-region-as-kill "$(xsel --clipboard --output)"
fi
zle .$WIDGET
}
zle_put_widgets=(
vi-put-after
vi-put-before
)
for widget in $zle_put_widgets; do
zle -N $widget __clipboard_putbuffer
done