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 Windows clipboard. Using various command-line 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 was 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 or another 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 -xclip -o 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 X Window 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 ⍼⍼
I use it to copy my writeup template for easy pasting into a new draft: cat ~/Documents/Writing/E2/template.e2 | xclip -selection clipboard
, which sends a copy of the existing file to my clipboard ready to use. I also use it to get the Discordian date: date | xclip -selection clipboard gives me Today is Boomtime, the 67th day of Chaos in the YOLD 3190 today.
Not running Linux? Well, Apple's OS should give you access to the zsh 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. I hope it works for ya! If not, I wonder if Cygwin's xclip would work for Windows =]
$ xclip -o | wc -w
441