It is possible to control the clipboard (copy and paste) from the command line in linux and OSX. In linux, the command is xsel, and in OSX, pbcopy/pbpaste.
For example, someone IMed me and asked for a subversion URL. Normally, I would type “svn info” in a terminal, use the mouse to select the URL, and press Ctrl-Insert to copy. Instead, I can just run this command:
svn info | grep URL | xsel --clipboard
Then, I can Alt-Tab back to the IM window and press Ctrl-v. There is no wasted time reaching for the mouse.
The—clipboard argument is required. Without it, xsel acts on the currently selected text in the terminal rather then the clipboard.
In OSX, the equivalent command is:
svn info | grep URL | pbcopy
pbcopy/pbpaste come with OSX. In debian flavors of linux, the following command will install xsel:
sudo apt-get install xsel
xsel can also be used to paste the clipboard. For example:
% echo ls | xsel --clipboard % xsel --clipboard ls % `xsel --clipboard` bin dev initrd lost+found mnt root sys var
3 Responses to “Command line clipboard access”
Sorry, the comment form is closed at this time.
There is also xclip (http://sourceforge.net/projects/xclip) for linux and othe POSIX compliant Unices.
On Windows, Cygwin comes with getclip and putclip which do the same job.
On Cygwin, you can also pipe to and read from ‘/dev/clipboard’ which is pretty cool.
Kevin, you rule!