Yay for pbcopy and pbpaste!

You know the feeling when you discover a trick of the trade that absolutely blows your mind and five minutes later you find out you are the last to the party and you should know it anyway? Well, that’s me with pbcopy and pbpaste, two OS X programs that make command-line copy and paste operations much easier and neater.

Let’s say you want to find all Ruby source files in a directory and copy the list to the clipboard (or pasteboard and OS X man page refers to it):

$ find . -name "*.rb" | pbcopy

Now if you want to see what’s in your clipboard you can use cat or less to display it:

$ pbpaste | less

Copy file contents to the clipboard:

$ pbcopy < cukes/features/support/hooks.rb

And from the clipboard to a file:

$ pbpaste > script.rb

I'm a keyboard aficionado and I really like to interact with computers without the need to move my hands off the keyboard to the mouse or trackpad, especially when all I need is to copy the output of the last command so any shortcuts or tricks are welcome. I think these two will be very handy in the future.