xcopy
xcopy - read and write text to/from an X selection from the command line
xcopy [ -r ] [ -u | -c ] [ -C ]
xcopy is a command-line utility for manipulating the X selection.
It has two basic modes. In read mode (xcopy -r), it connects to your X server, retrieves the contents of the selection as plain text, and writes it on standard output. You would then typically redirect its output into a file, or pipe it into some other program.
In write mode (just xcopy, if -r is not specified), it will read data from standard input, then connect to your X server and place that data in the selection as plain text. So you can pipe data into xcopy, move to another application, and press Paste.
The X selection model requires the selection-owning client to remain connected to the server and hand out its data on request. Therefore, xcopy in write mode forks off a background process which does this. The background process terminates once it is no longer the selection owner (i.e. as soon as you select data in another application), or if your X session finishes. Normally you can ignore its presence, although it might become important to be aware of it if (for example) the xcopy background process were to be the last X client still connected through an SSH tunnel.
xcopy currently only handles text data. However, it is capable of handling it in the form of plain text, UTF-8, or compound (multiple-character-set) text. Use the -u, -c and -C options to control this aspect of its behaviour.
By default (if -r is not supplied), xcopy operates in write mode.
-r
xcopy into read mode.
By default (if neither -c nor -u is supplied), xcopy reads and writes the selection using the type STRING, which means that the input or output data is expected to be encoded in ISO-8859-1.
-u
xcopy to request the selection using the type UTF8_STRING, which typically means that the returned data will be encoded as UTF-8. In write mode, causes xcopy to give out the selection as type UTF8_STRING, meaning that the data piped in to it is expected to be encoded as UTF-8.
-c
-u, but uses the type COMPOUND_TEXT rather than UTF8_STRING. COMPOUND_TEXT is a complex multi-character-set encoding similar to ISO 2022, and is unlikely to be a very useful form in which to pass data to or from non-X programs. However, it might occasionally be useful to retrieve a compound text selection using xcopy -r -c, and later on return it to the X selection using xcopy -c so it can be pasted back into a different application.
In write mode, if xcopy is operating in STRING mode and a pasting application requests the selection as COMPOUND_TEXT, xcopy will convert the data automatically. This is normally what you want.
-C
-C to disable conversion to compound text.
Occasionally xcopy -r completely fails to notice selection data owned by another process. I have not yet reproduced this reliably; if anyone can, some work with xmon(1) would be much appreciated...
Automatic conversion between compound text and UTF-8 is not currently supported. There are Xlib functions to do it, although they don't appear to work very well (missing out many characters which they could have converted).
xcopy is free software, distributed under the MIT licence. Type xcopy --licence to see the full licence text.