clipboard

For an overview of the X window system's approach to the clipboard, see Arch wiki - clipboard. The summary is that the clipboard is managed by X, and has three distinct selections.

  • PRIMARY: selected text, i.e. highlighted by mouse,
  • CLIPBOARD: text that is explicitly copied (e.g. by ctrl-c),
  • SECONDARY: no agreed upon purpose.

In order to manage these selections, install some command-line tool like xclip.

pacman -S xclip

For example, to copy a screenshot (taken with the package maim) to the clipboard,

maim --select --nodrag | xclip -selection clipboard -target image/png

Packages might also use xsel, so it's probably best to have both installed.

pacman -S xsel

losing history

By default, the clipboard contents are lost if the application the is data from is closed. For example, if one opens a terminal window, types some text, then copies the text, it can be pasted somewhere else. But once the terminal window is closed, one can no longer paste the text --- it is lost.

This is because X only stores references to the data, not copies. See the Ubuntu wiki for more information as well as this Reddit post. The Ubuntu article recommends Parcellite while the Reddit post recommends clipmenu. The Arch wiki also has a list of clipboard managers.

Most clipboard managers don't directly solve the persistence issue. Instead, they maintain a history of everything that is copied, and if the selection is lost, one can use a command-line interface or open a GUI to select a previous entry and re-copy it to the clipboard.

But I don't want to have to manually re-copy the last thing I copied, I just want to be able to keep the entry in my clipboard if I close the application. I couldn't get clipmenu or clipcat to work like this.

xclipboard, the official X clipboard manager works, but it always launches a GUI window that can't be easily suppressed. Parcellite works but it's old and relies on GTK2. A modern replacement is ClipIt, but when I used it reminded me that there was a security concern: I sometimes copy passwords and other sensitive information to the clipboard, and all of these clipboard managers store data on disk as plaintext in a temporary directory. I wanted to find a clipboard manager that supported clipboard persistence without manual intervention while storing data only in memory, never touching disk.

For these reasons, I settled on clipster.

copy/paste

One can use the open-source tmk/qmk firmware to bind physical keys to copy/paste. The relevant keycodes are KC_CUT, KC_COPY, and KC_PASTE. The X keyboard event viewer xev (pacman -S xorg-xev) shows that these are mapped to XF86Cut (145) XF86Copy (141), and XF86Paste (143), respectively. Support for these keys seems to be built-in to X as well as most GUI applications.