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

Use copy/paste as much as you can

Dear new developer,

Use copy and paste as much as you can. Not so much for code snippets from Stackoverflow, though that will save you some time hunting down mismatched parentheses.

But this is especially useful whenever you are searching for errors or moving information between systems.

For example, recently I had to find where java was installed and set the JAVA_HOME environment variable. I could have typed it in, but that is error prone. More than once I’ve transposed or omitted letters. Whenever I’m doing this kind of adhoc software configuration, I use copy/paste.

I also use this a lot when preparing to file an issue or ticket. First, I’ll just copy and paste the error message (removing the particulars of my system like file paths) into Google to see what pops up.

Then, if it is still an issue and I don’t see any answers, I’ll pop open a text editor and cut and paste all my notes about the issue, what I’ve tried (which often leads to more avenues to explore, rubber ducking in action), logfile lines. All this would be hellish to type, so I copy and paste away.

I hear there are systems out there with more than one clipboard spot, but I’ve always gotten by with the system clipboard. I did recently discover the magic of pbpaste and pbcopy on the mac, which let you copy file contents to the system clipboard (and it looks like there are analogs for other systems).

Anyway, make sure you know and love your system clipboard. When you are trying to copy complicated text, you’ll thank me.

Sincerely,

Dan