It is a program that simply exits whenever an X selection changes.
So put it in a while loop and when it exits, figure out if the clipboard or
the primary changed, and stuff the contents of the changed selection in the other
selection.
get_selections_keep_newline() {
c2=$(xsel -o --clipboard; printf x)
c2=${c2%x}
p2=$(xsel -o --primary ; printf x)
p2=${p2%x}
}
get_selections_keep_newline
while clipnotify; do
c1=$c2
p1=$p2
get_selections_keep_newline
if [ "$c1" != "$c2" ]; then
printf '%s' "$c2" | xsel -i --primary
elif [ "$p1" != "$p2" ]; then
printf '%s' "$p2" | xsel -i --clipboard
fi
done
Save it as mergexsel
, make it executable and let it run.
The function contains a kludge to preserve trailing newline characters
(abc\n
is different from abc
); other than that the script is self-explanatory.
It must be run for both primary and clipboard (as this answer on Super User shows).
autocutsel -s CLIPBOARD &
autocutsel -s PRIMARY &
Diodon, a GUI clipboard manager
Let it run in the background with diodon &
.
Click the tray icon or issue another diodon
command to pop up its GUI menu
with the history of clipboard contents and the "Preferences" item. Select "Preferences" and in the window that opens, check the items
Use clipboard (Ctrl+C)
Use primary selection
Synchronize clipboards
Further reading: Clipboard — Arch Wiki for context and more clipboard managers.