If you select text with simple drag, it goes into what I usually call the 'soft' buffer - you can paste it with a simple middle mouse click, but the moment you select anything else it's gone.
On the other hand, gnome and KDE and other WMs generally also let copy selected text into a 'hard' buffer where it stays until you explicitly copy something else into it.
Programs like Firefox don't so much maintain the Xorg selection as that they add a selection mode of their own that just happens to coincide with it -- for example, if you select text in firefox, then select something in another window, then go back to FF and middle click to paste, you'll get the latter text.
Bash's clipboard is internal to bash, bash doesn't connect to the X server.
What you could do is change the meaning of M-w
to copy the selection to the X clipboard¹ in addition to bash's internal clipboard. However bash's integration is pretty loose, and I don't think there's a way to access the region information or the clipboard from bash code. You can make a key binding to copy the whole line to the X clipboard.²
if [[ -n $DISPLAY ]]; then
copy_line_to_x_clipboard () {
printf %s "$READLINE_LINE" | xsel -ib
}
bind -x '"\eW": copy_line_to_x_clipboard'
fi
If you want to do fancy things in the shell, switch to zsh, which (amongst other advantages) has far better integration between the line editor and the scripting language.
if [[ -n $DISPLAY ]]; then
x-copy-region-as-kill () {
zle copy-region-as-kill
print -rn -- "$CUTBUFFER" | xsel -ib
}
x-kill-region () {
zle kill-region
print -rn -- "$CUTBUFFER" | xsel -ib
}
zle -N x-copy-region-as-kill
zle -N x-kill-region
bindkey '\C-w' x-kill-region
bindkey '\ew' x-copy-region-as-kill
fi
¹
Gnome doesn't specifically have a clipboard, this is general to X.
²
As of bash 4.1, there is a bug in the key parsing code: key sequences bound with bind -x
may not be more than two characters long. I think bash 4.2 fixes some cases of longer prefixes but not all of them; I haven't researched the details.
Best Answer
They are part of Selection Atoms, or X Atoms.
The Inter-Client Communication Conventions Manual for X states:
In short:
Read more here.
Support for PRIMARY was added to WebKit back in 2008.
xclip
, which is a command line interface (tool) for X selections (clipboard), traditionally adds data to Primary Clipboard. Optionally one can choose which one to use by the-clipboard
option given argument of either.Corr.: Drag And Drop resides under Xdnd. There is also a Wikipedia entry on the spec. It uses XdndSelection and should not interfere with PRIMARY.
The protocol is at least implemented by Qt and GTK.