Clipboard Filtering

April 14th, 2024
cli, tech
Here's a pattern I find pretty useful:

pbpaste | some_command | pbcopy

For example:

  • Converting spaces to tabs, for pasting into a spreadsheet program: pbpaste | tr ' ' '\t' | pbcopy

  • Converting tabs and newlines to html table formatting: pbpaste | sed 's/^/<tr><td>/' | sed 's/\t/<td>/g' | pbcopy

  • Escape angle brackets and ampersands for html: pbpaste | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g;' | pbcopy (I used this on itself before pasting into this post.)

  • Convert newlines-indicate-paragraphs text to html: pbpaste | sed 's/^/<p>/' | pbcopy (I use this in putting together the kids text posts.)

  • Any time I want to do find-and-replace when working with software that doesn't support it well.

The way this works is that pbpaste reads from the clipboard as plain text, the intermediate command(s) transform the text, and the pbcopy sends it back to the clipboard.

While these are the Mac commands it should be similar elsewhere. For example, on Linux I'd use xsel, though that does require paying attention to whether you want PRIMARY (xsel) or CLIPBOARD (xsel -b).

Comment via: facebook, lesswrong, mastodon

Recent posts on blogs I like:

Starting With Chords

A lot of people play fiddle. Basically nobody starts by learning chords before learning melodies. But that's actually how I learned. I started with chords. One of the nice things about learning to play violin this way is that you can go busking even…

via Anna Wise's Blog Posts November 15, 2024

Stuffies

I have some stuffies and I just have a bunny. Bunny is a rabbit. Woof is a seal. My favorite stuffie is bun bun. I play with my stuffies. Sometimes I jump up with them and I roll them. I can just throw them in the air when I want to play bthululubp wi…

via Nora Wise's Blog Posts November 15, 2024

You Can Buy A Malaria Net

2024 election takes

via Thing of Things November 6, 2024

more     (via openring)