A Linux command-line tool to access the clipboard
"command line interface to X selections (clipboard) "
— xclip man pages
In short, this Linux command-line tool is used to access the X WIndow clipboard. Using various commandline options, it's possible to copy from or to various X clipboards. As with many such tools, it's often used to pipe to or from other commands. In fact I use it this way to generate an accurate word count for each of my writeups, as seen below.
$ xclip -h
Usage: xclip [OPTION] [FILE]...
Access an X server selection for reading or writing.
-i, -in read text into X selection from standard input or files (default)
-o, -out prints the selection to standard out (generally for
piping to a file oranother program)
-l, -loops number of selection requests to wait for before exiting
-d, -display X display to connect to (eg localhost:0")
-h, -help usage information
-selection selection to access ("primary", "secondary", "clipboard" or "buffer-cut")
-noutf8 don't treat text as utf-8, use old unicode
-target use the given target atom
-rmlastnl remove the last newline character if present
-version version information
-silent errors only, run in background (default)
-quiet run in foreground, show what's happening
-verbose running commentary
To understand its value, here's the command line I use to count words: xclip -o | wc -w|xclip -rmlastnl -selection clipboard. I copy the displayed text from E2 and just hit that command. xclip grabs the clipboard contents (the displayed writeup, pipes it to wc (which counts the words!), the output of that is piped to xclip again, which removes the trailing newline and pumps it to the xWIndow clipboard, ready to paste into the writeup. Easy, takes me seconds, and all I have to do is come back to E2 and paste it in the correct place ⍼ ⍼
Not running Linux? Well, Apple's OS should give you access to the command line, and I just bet that xclip is included in there. Windows has the Windows Subsystem for Linux and boy howdy, you bet that any Linux distro you install will have it too. xclip -o | wc -w | xclip -rmlastnl -selection clipboard gives me the wordcount of the clipboard contents, which I use for each of my writeups. ddate | xclip -selection clipboard allows me to get the Discordian date: Today is Setting Orange, the 57th day of Discord in the YOLD 3190
.
$ xclip -o | wc -w
367