Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy the GNU Screen copy buffer to the clipboard? [closed]

When using GNU Screen we can work with scrollback buffer also known as "copy mode" using the Ctrl+a+[ command.

In there we can copy text to the copy buffer by pressing space selecting the text and pressing space again.

Is there some way to copy this text from screen copy buffer to the X clipboard?

In my case I'm using Ubuntu 12.04 with gnome and Xorg.

like image 804
Samuel G. P. Avatar asked Apr 19 '13 18:04

Samuel G. P.


People also ask

How do you scroll up in Linux screen?

To scroll up within a screen window, use this command: CTRL+a then ESC, #Press CTRL KEY and 'A' KEY together and then hit the ESC KEY #to scroll using the arrow keys hit ESC again to exit.


2 Answers

You can use a CLI clipboard tool like xsel or pbpaste and the cat utility to grab contents from STDIN. The steps on Linux with xsel are as follows:

  1. Copy text from your screen session into GNU screen's copy buffer.
  2. Run this command within screen: cat | xsel -b
  3. If xsel didn't report any error, now dump screen's copy buffer to STDIN: Ctrl+a+]
  4. Send an EOF to cat to terminate it: Ctrl+d

At this point, the contents of the screen copy buffer should be in your clipboard.

EDIT: As with all X programs, xsel needs to know how to contact your X server in order to access the clipboard. You should have your DISPLAY environment variable set appropriately.

like image 126
bonsaiviking Avatar answered Sep 16 '22 15:09

bonsaiviking


This answer works for only a scenario where your end target is to paste the copied buffer contents immediately.

The simplest way to do this is by splitting your screen into two regions. You can do this by hitting CTRL+a then |'This is not an i. It is the PIPE sign on your keyboard'

Hit CTRL+a then TAB to switch to the second region, CTRL+a then c to create a new session in the second region.

If you want to copy from nano and paste in terminal, open up the file in nano on the left region, hit CTRL+a then ESC, scroll to the start point of your copy location and hit SPACE, select the text by scrolling to the end point and hit SPACE again to mark copy.

Now, all you have to do is hit CTRL+a then TAB to switch to the region on your right and hit CTRL+a then ].

Your text will be written out to the command line. Note that you can also check for hardcopy option if you want to write directly to file.

like image 30
CoderX Avatar answered Sep 18 '22 15:09

CoderX