arminstraub.com

KDE clipboard on the command line

The python script clip.py.gz makes it easy to use the KDE clipboard on the command line.
(In this context, the clipboard is understood to be exactly what is offered by klipper).

Basic usage

For the following examples it is assumed that the script is available in the search path as clip.
  • clip
    gives the content of the clipboard. You can use the switch -i 2 to obtain historic contents, here item number 2, of the clipboard (note that -i 0 refers to the current content).
  • clip "some text"
    Put "some text" into the clipboard.
  • ps | clip -
    Put the output of some program, here ps, into the clipboard.

Some examples

  • ssh $(clip)
    Connect to the server whose hostname is contained in the clipboard.
  • clip long_file_name
    Use the autocompletion of the shell to copy filenames conveniently to the clipboard.
  • cat todo | clip -
    Copy the content of files, here todo, to the clipboard.

Download

LinkSizeDescriptionHits
971 Bytes clip for KDE4 1602
977 Bytes clip for KDE3 1283

To use the python script clip.py.gz as described above:

  • unzip the file (gunzip clip.py.gz),
  • rename it to clip,
  • give yourself execute permission (chmod +x clip), and
  • place it in a folder, which is in the search path of the shell.

KDE3 vs. KDE4

The attached clip.py.gz is using dbus and works for KDE4. If you are still using KDE3, you can download clip-kde3.py.gz.