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

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


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.


This answer applies to OS X.

After copying the desired text into the GNU Screen paste buffer using copy mode, do the following:

  1. In any of your screen windows, type pbcopy <enter>.
  2. Then paste your text into the terminal using the GNU Screen paste command (Ctrl-a ] unless you've changed your escape key).
  3. If the text does not end in a newline, press <enter> to insert one.
  4. Finally, press Ctrl-d to cause pbcopy to push the text to the system clipboard.

Then you can paste the text elsewhere in OS X as usual using Command-v or an equivalent menu option.


There is a simpler and less manual way to do this. In your screen .rc file, add the following line:

bindkey -m ' ' eval 'stuff \040' 'writebuf' 'exec sh -c "/usr/bin/pbcopy < /tmp/screen-exchange"'

How to use the copy functionality:

  1. screen -c path/to/screen/config.rc
  2. Hit Ctrl+A then Esc to enter copy mode.
  3. Scroll up the text buffer and find the spot you want to leave your start marker for copying, then hit space.
  4. Scroll down and select the text you wish to copy. When you are done, hit space again.
  5. The text will now be in your clipboard.

EDIT: On Linux with no pbcopy but with clipit, you can use as below:

bindkey -m ' ' eval 'stuff \040' 'writebuf' 'exec sh -c "/bin/cat /tmp/screen-exchange | /bin/clipit"'