Hone Your Desktop Clipboards with Parcellite on Linux


If you’re a normal desktop Linux user, it has probably been while since you thought about the X Window System. Modern distros let you configure your video card without ever touching xorg.conf, and by and large the window managers and GUI toolkits just work without getting in your way. But there is still one lingering pain point: the clipboard. Between most user apps, cut, copy and paste work without a hitch, but terminals, text editors like Emacs and Vim, and a few other stragglers refuse to cooperate. If that sounds familiar, consider checking out Parcellite.

Parcellite is a lightweight clipboard manager that sits unobtrusively in the top panel, but smooths over the rough spots of inter-app cut-and-paste behavior. The latest version is 1.0.2, which fixes a few bugs that slipped in after the recent 1.0 stable release. You can get source code packages on the project’s download site, but there is a pretty good chance your distribution already packages it. Distro-provided packages might not include the latest release, simply due to how recent it is, however.

Whether or not it is worth installing from source depends on your exact needs. 1.0.x adds a few interesting features over the 0.9 series provided by most distros, such as the ability to search through Parcellite’s clipboard history in as-you-type mode, and the ability to reposition where the clipboard history pop-up appears. Neither one of those is core functionality, but your mileage may vary. If you do build from source, Parcellite depends on basic GNOME stack libraries: GTK+, Pango, Cairo, etc.; nothing out of the ordinary.

Get Clippy

At the heart of Parcellite’s behavior is its ability to synchronize the two distinct X selection methods: the CLIPBOARD selection and the PRIMARY selection. In typical X fashion, the official designations for both are in all caps, so we’ll use that format to distinguish them from generic usage of either term.

The PRIMARY selection is whatever is highlighted by the cursor; you often see this functionality when you highlight text in a terminal window using the mouse. Mouse-1 (the left button) starts the selection, Mouse-2 (the right button) ends it, and Mouse-3 (the middle button) inserts the selection. This old relic is still useful today because the keyboard shortcuts Control-C and Control-X are often captured by the shell and mapped to other functions if you type them inside a terminal window, but mouse clicks aren’t.

In contrast, the CLIPBOARD selection is what is copied whenever you explicitly give a “copy” command to the current app — generally by Control-C or a button press, but potentially a different key combination. Yes, the world would be simpler if PRIMARY and CLIPBOARD were always the same, but that isn’t going to happen any time soon.

You can launch Parcellite from the command line with parcellite —. The current version places a clipboard icon in the GNOME 2 panel’s notification area; no word yet on an app-indicator for Unity or a GNOME Shell port. When in use the panel icon is essentially a system-wide clipboard menu: click it and you’ll get a history of your copied items (25 entries long, by default), from which you can select whichever suits your fancy. The history is preserved across sessions, which is a nice touch.

Right-click on the icon to open the preferences dialog. The Behavior tab hold the important options. At the top, the “Clipboards” section has three checkboxes: one for “Use Copy” (which makes Parcellite watch CLIPBOARD), one for “Use Primary” (which watches PRIMARY), and one for “Synchronize clipboards (which keeps them in sync with each other). That is the core of the magic, of course, but the other options are worth looking at, too.

You can set how many history items to save — including none, in which case Parcellite just syncs CLIPBOARD and PRIMARY to whichever is most-recently-used — plus alter where the history list pops up (which honestly I have not discovered a use-case for). Another use case entirely is available in the “Miscellaneous” section, where you can have Parcellite copy only URLs to the history. That can be useful if you share a lot of links. Miscellaneous also lets you toggle on the search-as-you-type functionality, which can be good if you like to save a lengthy history.

Finally, the Display tab allows you to tweak a few display settings, such as the sort order (newest-to-oldest or vice versa), how many characters wide to make the history pop-up, and whether to truncate the beginning, middle, or end of selections that are too long.

Clipboarding for Pros

If all you care about is freeing up the mental energy you used to expend keeping CLIPBOARD and PRIMARY straight in your mind, you’re all set. But Parcellite has a few other tricks up its sleeve.

For one thing, despite the fact that the history menu shows you your actual selections, it also makes them all editable. That’s not particularly handy if you’re cutting and pasting in an email, but when you’re writing something complex (code, an article, your new free software license), it can turn the clipboard into a handy saved-block-of-text storage system. Particularly when writing tutorials, I reuse lots of HTML fragments to mark up commands (imagine a long ifup command, littered with <code> and <em> tags). With Parcellite I can write the first one, copy it, then cut down the selection to just the generic portion and re-use it at will.

Parcellite also supports configuring “actions” (i.e., custom commands) that take the clipboard selection as an argument. The simplest example would be an action like wget %s — the %s variable is replaced by the selection, so whenever you copy a URL, you can bring up Parcellite’s actions menu and download it with one click. Users can also write actions to perform search-and-replace, dictionary lookup, or anything else. By default, Control-Alt-A opens the actions menu, but this is configurable.

Another nice touch is that Parcellite is usable from the command line. So if you have to SSH into your machine from a remote location, you can retrieve your clipboard history, or add to it. From a shell, you can type echo "http://some.url.youll/otherwise/forget" | parcellite and the URL will be added to your Parcellite selection history. Type parcellite -c to see your CLIPBOARD history, and parcellite -p to see your PRIMARY history (although naturally they will be the same if you sync them).

Extra Credit

If you ask me, Parcellite’s ability to unify the two main X selection methods is something that really ought to be built right into GNOME and the other desktop environments; it’s just that useful, and I’ve never had occasion to want the two to be separate. On the other hand, I do use Emacs every day, and I really like having Emacs’ slightly-different “kill” and “yank” behavior available when I’m writing. Owing to its heritage, Emacs is one of those programs that, like the terminal, has always exposed the difference between CLIPBOARD and PRIMARY.

You can use Parcellite with Emacs naively to keep the program’s kill-ring synchronized with the system-wide clipboard, but if you’re a heavy Emacser, you may want some more flexibility. For that, EmacsWiki.org has a nice summary of the copy-and-paste options and how they affect Emacs’s interaction with the system clipboard — and thus, with Parcellite.

Personally, I’ve never been unlucky enough to have to use Vim, but if that lot does befall you, I would recommend looking at the corresponding page on the Vim wiki for a detailed look at that application’s copy and paste behavior. It, like Emacs, has different expectations of CLIPBOARD and PRIMARY, which can lead to conflicts if you’re not careful.

These days, most other common applications with sync with Parcellite without incident, but if you do find another one with its own brand of clipboard behavior, be sure to share it. Parcellite is under active development again (after a few years off following the 0.9 series), so your feedback could improve the app and help out some other user at the same time.