Sending data to the clipboard from command line

26 Apr

In several occasions I find myself catting some file and then having to select the entire text with the mouse. If I want to keep my hands on the keyboard, I have to do a vim file, ggVG, “+y, :q.

Well, I found a way to do it faster and nicer simply by piping to the clipboard, thanks to xclip.

To use it, just install it and configure an alias in your .bashrc file, as follows:

$ sudo apt-get install xclip
$ alias clipboard='xclip -selection clipboard'

Then, when you need to do something like configuring your SSH key in GitHub, you just:

$ cat ~/.ssh/id_rsa.pub | clipboard

Thanks to Brian Racer for this snippet!

Advertisements

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

%d bloggers like this: