pbcopy and pbpaste


pbcopy and pbpaste are two very simple shell commands that help you to streamline your copy & paste operations.

pbcopy copies stdin to the OSX clipboard. pbpaste copies the clipboard content to stdout. Combining both allows you to perform complex operations on your clipboard contents. Need an example:

pbpaste | fmt -s -w 80 | pbcopy

will format the text in your clipboard so that it breaks at a text width of 80 characters. very good if you need to write technical documents with fixed character width. I guess you can easily imagine any text-based workflow. Just think of what stream processing you can do with html tidy, aspell, etc.

Of course, putting your pbpaste/pbcopy chain to a script that you can conveniently run from any shell or binding it to a key combination will make the whole thing even more useful.

I found this works for OSX. Maybe there is an equivalent for Linux as well. Any hints?

About these ads

One thought on “pbcopy and pbpaste

  1. For Linux there’s xclip, so the command would work like this:

    xclip -o|fmt -s -w 80|xclip -i

    Great idea btw. I usually just use vim to rebreak any mails/documents I might receive, but this is handy too.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s