Use the clipboard from the command line

Dear new developer,

I’ve already written about the power of copy/paste to save effort. And had a guest blogger write about how you should be focus on inspiration rather than imitation.

This letter is going to be extremely tactical and reveal to you two commands that I didn’t know until a year or so ago.

But they changed my life. Well, they at least made my work copy/paste routine better. And reduced my mouse usage.

I spend a lot of time in a terminal, on the command line, but often want to copy between a terminal and a browser.

I might want to do this to paste an error message into a search engine. Or copy and paste a config file into a stack overflow question. Or even just type up something in a text file and copy and paste it into slack so that I can write something thoughtful without dealing with slack’s horrendous editing interface.

To do so, you can use these commands:

On macos, pbcopy. On Windows, clip.

Before I discovered these commands, I used to select text with my mouse and copy it, then paste it. It worked, but was inefficient.

Now, if I’m writing that aforementioned thoughtful response to a slack message, I might do the following:

vi a
# write thoughtful response
cat a | pbcopy
# cmd tab
# paste to slack
rm a

I use the temporary filename a because as soon as I finish writing it, I’ll be copying it to slack, which is where the thought will live permanently. But I still get to use my text editor.

Again, you can use this for any kind of text that you want to copy from the command line into the system clipboard. Error logs, sample commands, text files, configuration, anything. Copy it all!

Hope this helps,

Dan