I want to copy some text from screen to my clipboard. I know how to get into copy and paste mode in screen, but I want that text to go to my clipboard so I can paste it on the browser, for example.
How do I do this? Thanks!
In most programs, you would select text and press Ctrl + C to copy it. Pasting text would be done by pressing Ctrl + V. In the terminal emulator program, Ctrl + C has a special meaning, it interrupts (stops) programs by default.
Your terminal emulator program may have other shortcuts defined. For example, Konsole and Gnome Terminal uses Ctrl + Shift + C for copying the selected text. Alternatively, select text and copy it by using the Copy option in the Edit menu or the context menu.
If the output of your program is large, you might want to enable the scrollback buffer of
screen. That can be done by adding the below line to the
termcapinfo xterm ti@:te@
For a raw and dirty implementation, install the package
xsel, that allow command line interaction with then X clipboard, then put these lines in your
bind > eval writebuf "exec sh -c 'xsel -nbi </tmp/screen-exchange'" bind y eval "exec sh -c 'xsel -bo >/tmp/screen-exchange'"
Now, when you select something in
screen copy/scrollback mode, and write paste buffer to a file with C-a >, you can move to the browser and paste the content of the clipboard as usual (for example with Ctrl-V).
For the reverse, copy something in your browser with Ctrl-C, then go to
screen and read the clipboard with the new command C-a y, then read the screen-exchange file into the paste buffer with C-a <, finally paste wherever you want with C-a ].
For this to work the variable
DISPLAY must be correctly set, and you must have access to the X server. This is not a problem when you are on a terminal running on the same X server, but if you run
screen in a virtual terminal, e.g. tty1, then you may need to run
xhost + on the X side, and
export DISPLAY=:0 or similar on the terminal, before starting
As you see, it is not simple, and not bullet proof, but I hope it can help.
This answer is partly inspired from synchronizing GNU screen’s paste buffer and the X selection
Just use copy operation in your terminal application. If you are using gnome-terminal for example, just select test and use context menu -> copy.