-
Notifications
You must be signed in to change notification settings - Fork 21
/
clipboardsync
executable file
·48 lines (37 loc) · 1.35 KB
/
clipboardsync
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
#!/bin/bash
#this script uses xsel to synchronize the clipboards of the host X server and the guest's Xephyr window.
errorexit(){
echo $1
exit 1
}
[ ! -f /usr/bin/xsel ] && errorexit "xsel not installed!"
hostdisplay=':0'
guestdisplay=':1'
while ! xsel --display $guestdisplay -b -o &>/dev/null;do
sleep 1
done
echo "Guest X server started. Running..."
#update guest's clipboard at startup
xsel --display $hostdisplay -b -o | xsel --display $guestdisplay -b -i
guestprevclip="$(xsel --display $guestdisplay -b -o)"
hostprevclip="$(xsel --display $hostdisplay -b -o)"
while true;do
xsel --display $guestdisplay -b -o &>/dev/null || exit 0
xsel --display $hostdisplay -b -o &>/dev/null || exit 0
guestcurclip="$(xsel --display $guestdisplay -b -o)"
hostcurclip="$(xsel --display $hostdisplay -b -o)"
#if host's clipboard was changed this time
if [ "$hostcurclip" != "$hostprevclip" ];then
#update the guest's clipboard
xsel --display $hostdisplay -b -o | xsel --display $guestdisplay -b -i
#if guest's clipboard was changed this time
elif [ "$guestcurclip" != "$guestprevclip" ];then
#update the host's clipboard
xsel --display $guestdisplay -b -o | xsel --display $hostdisplay -b -i
fi
#shift register
guestprevclip="$guestcurclip"
hostprevclip="$hostcurclip"
#wait a bit between each loop sequence
sleep 0.1
done