12 May 2010

+rw clipboard

I saw some guy do a cat on some file (directly into his clipboard) and then paste/ctrl-v the text into his editor. My brain immediataly went "gimme! gimme! gimme!"



After a little googling around I found that his tools, pbcopy/pbpaste, was exclusively for OS X. A few minutes more with google showed me that the tool for the job in Ubuntu was xsel


#apt-cache search xsel
xsel - command-line tool to access X clipboard and selection buffers


However xsel covers both read and write and uses parameter to distinct them. My brain isn't up for the job remembering parameters so I decided Steve Jobs'es command was my way. Alias will fix this right up and I have pbcopy and pbpaste and feel happy and warm inside.


get xsel
#sudo apt-get install xsel

Here are the commands:
#cat myfile.txt | xsel -ib
#xsel -o > mycopy.txt


put these two lines into ~/.bashrc if you want this the OS X -way.

alias pbcopy='xsel -ib'
alias pbpaste='xsel -ob'

Do it like apple does:
#cat myfiles.txt | pbcopy
#pbpaste > mycopy.txt


/Finn


edit.(15.04.2011) For some reason the xsel with Ubuntu 10.10. needs xsel -ib (not just xsel -i). No idea why, but blog post is updated accordingly.