14

Say I've typed the following long command into the command line

 $ some very long command that I want to copy to the clipboard

How can I get this onto the system clipboard efficiently? I'm using Gnome Terminal 2.23.1.

I know that I can get the mouse and highlight it and copy it, but I want a general keyboard solution.

It would also be good if it generalised to multiple command-line programs.

For example, in bash in vi mode, I can press v and then edit the command in vim, and thus use Vim's copy to clipboard features, but this doesn't work when using R on the command-line. It's also a bit slow.

I'd like it if in vi-mode, I could press yy and copy the contents of the line to the system clipboard, but this doesn't seem to work. Furthermore any yanking commands don't seem to copy contents to the system clipboard; they appear to only copy to a buffer used by bash.

UPDATE:

After posting I found

3 Answers3

3

You could also use a clipboard manager like parcellite. It's a GTK+ clipboard manager which also has command-line clipboard capabilities

You can use it via command-line by

echo "some very long command that I want to copy to the clipboard" | parcellite
##or##
parcellite "some very long command that I want to copy to the clipboard"

It is not installed by default and so you'll have to install parcellite by sudo apt-get install parcellite

1

So the closes I have be able to get is by using the history and xclip in conjunction doing this

echo !! | xclip

This will put the last command on the the center button clipboard. I am still searching for something better though as I would like to get it down to one command. However I get hung up because history doesn't function in shell scripts and I don't know that there is a way to use !! properly in an alias. Of course this doesn't appear to be quite what your asking for my intention is to use this for taking notes of what I am doing. Any thoughs?

user27643
  • 111
0

You should be able to use Ctrl+Shift+C for Copy and Ctrl+Shift+V for Paste anywhere in the Terminal.

Eliah Kagan
  • 119,640