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.
-b
xcopy to read or write the clipboard instead of the selection. (Modern GNOME and KDE-style programs can often interact with both. The selection is the traditional X-style storage location which you typically copy things into just by selecting them with the mouse, and paste with the middle mouse button. The clipboard is a more Windows-like location which you access using explicit Cut, Copy and Paste commands in your application.)
-t
xcopy, in read mode only, to return the list of possible target types currently stored in the selection. This is probably only useful for debugging X applications or X selection issues.
-T
xcopy, in read mode only, to return the time stamp for the current selection. This is probably only useful for debugging X applications or X selection issues.
-a target atom
xcopy, in read mode only, to return the selection contents corresponding to some particular user-specified target type. The target type can be anything listed by ‘xcopy -r -t’.
-v
xcopy, in read mode only, to produce a verbose commentary on the progress of reading the X selection. Can be useful for debugging interactions with other programs.
-T
xcopy not to fork, when in write mode. Instead the original xcopy process will continue to run until the selection is taken away from it. Probably only useful when debugging xcopy itself, although it's just possible that it might turn out to be useful for some other special purpose (e.g. having the process waiting for it know when the selection owner has changed).
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.