Skip to content

Instantly share code, notes, and snippets.

@Defelo
Created April 4, 2020 08:57
Show Gist options
  • Save Defelo/91e78cfac3fcb7474b4d009ed1f9872f to your computer and use it in GitHub Desktop.
Save Defelo/91e78cfac3fcb7474b4d009ed1f9872f to your computer and use it in GitHub Desktop.
X11 Clipboard Sync
#!/bin/bash
[[ $# -lt 2 ]] && echo "usage: $0 <first display> <second display>" && exit 1
clipread() {
xclip -selection clip -r -o -display $1 2> /dev/null
}
clipwrite() {
xclip -selection clip -r -i -display $1
}
clipboard=
update() {
content=$(clipread $1)
if [[ "$content" != "$clipboard" ]]
then
clipboard=$content
clipwrite $2 <<< "$content"
fi
}
while true
do
update $1 $2
sleep .1
update $2 $1
sleep .1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment