forked from martanne/vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vis-clipboard
executable file
·104 lines (79 loc) · 1.33 KB
/
vis-clipboard
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
#!/bin/sh
# Copyright (C) 2016 Richard Burke, ISC licensed
vc_fatal() {
echo "$@" >&2
exit 1
}
vc_usage() {
vc_fatal "`basename $0` [--usable|--copy|--paste]"
}
vc_determine_command() {
if [ -n "$DISPLAY" ]; then
for c in xclip xsel; do
if type "$c" >/dev/null 2>&1; then
echo "$c"
return 0
fi
done
elif type pbcopy >/dev/null 2>&1; then
echo 'mac'
return 0
elif [ -c /dev/clipboard ]; then
echo 'cygwin'
return 0
fi
return 1
}
vc_usable() {
if vc_determine_command >/dev/null 2>&1; then
exit 0
fi
exit 1
}
vc_copy() {
COPY_CMD="`vc_determine_command 2>/dev/null`"
if [ $? -ne 0 ] || [ -z "$COPY_CMD" ]; then
vc_fatal 'System clipboard not supported'
fi
vc_${COPY_CMD}_copy
exit $?
}
vc_paste() {
PASTE_CMD="`vc_determine_command 2>/dev/null`"
if [ $? -ne 0 ] || [ -z "$PASTE_CMD" ]; then
vc_fatal 'System clipboard not supported'
fi
vc_${PASTE_CMD}_paste
exit $?
}
vc_xsel_copy() {
xsel -bi
}
vc_xsel_paste() {
xsel -bo
}
vc_xclip_copy() {
xclip -selection clipboard -i >/dev/null 2>&1
}
vc_xclip_paste() {
xclip -selection clipboard -o
}
vc_mac_copy() {
pbcopy
}
vc_mac_paste() {
pbpaste
}
vc_cygwin_copy() {
cat >/dev/clipboard
}
vc_cygwin_paste() {
cat /dev/clipboard
}
case "$1" in
--usable) vc_usable;;
--copy) vc_copy;;
--paste) vc_paste;;
*) ;;
esac
vc_usage