How to copy the GNU Screen copy buffer to the clipboard?

copy-paste, gnome-terminal, gnu-screen, linux, terminal

Solution

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:

- Copy text from your screen session into GNU screen's copy buffer.

- Run this command within screen: `cat | xsel -b`

- If `xsel` didn't report any error, now dump screen's copy buffer to STDIN: `Ctrl+a+]`

- 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.

Problem

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.

Original source