Linux 如何将 GNU Screen 复制缓冲区复制到剪贴板?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16111548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:45:19  来源:igfitidea点击:

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

linuxterminalcopy-pastegnu-screengnome-terminal

提问by Samuel G. P.

When using GNU Screenwe can work with scrollback bufferalso known as "copy mode"using the Ctrl+a+[command.

使用GNU Screen 时,我们可以使用该命令处理回滚缓冲区,也称为“复制模式”Ctrl+a+[

In there we can copy text to the copy bufferby pressing spaceselecting the text and pressing spaceagain.

在那里,我们可以通过按下选择文本并再次按下来将文本复制到复制缓冲区spacespace

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

有没有办法将此文本从屏幕复制缓冲区复制到 X 剪贴板?

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

就我而言,我将 Ubuntu 12.04 与 gnome 和 Xorg 一起使用。

采纳答案by bonsaiviking

You can use a CLI clipboard tool like xselor pbpasteand the catutility to grab contents from STDIN. The steps on Linux with xselare as follows:

您可以使用 CLI 剪贴板工具(如xsel或 )pbpastecat实用程序从 STDIN 抓取内容。Linux上的步骤xsel如下:

  1. Copy text from your screen session into GNU screen's copy buffer.
  2. Run this command within screen: cat | xsel -b
  3. If xseldidn't report any error, now dump screen's copy buffer to STDIN: Ctrl+a+]
  4. Send an EOF to catto terminate it: Ctrl+d
  1. 将屏幕会话中的文本复制到 GNU screen 的复制缓冲区中。
  2. 在屏幕中运行此命令: cat | xsel -b
  3. 如果xsel没有报错,现在将屏幕的复制缓冲区转储到标准输入:Ctrl+a+]
  4. 发送一个 EOFcat来终止它:Ctrl+d

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

此时,屏幕复制缓冲区的内容应该在您的剪贴板中。

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

编辑:与所有 X 程序一样,xsel需要知道如何联系您的 X 服务器才能访问剪贴板。您应该DISPLAY适当地设置环境变量。

回答by John

If it's just a little bit of info that you want to copy just highlight it with your mouse and then paste it where you want.

如果您只想复制一点信息,只需用鼠标突出显示它,然后将其粘贴到您想要的位置。

If you're trying to get a lot of info the screen session can be logged to a file and then you can copy from the file or clean it up a bit and use it for instructions on doing things

如果您想获取大量信息,可以将 screen 会话记录到文件中,然后您可以从文件中复制或稍微清理一下,然后将其用于执行操作的说明

回答by scottgwald

This answer applies to OS X.

此答案适用于 OS X。

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

使用复制模式将所需文本复制到 GNU Screen 粘贴缓冲区后,执行以下操作:

  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-dto cause pbcopyto push the text to the system clipboard.
  1. 在任何屏幕窗口中,键入pbcopy <enter>
  2. 然后使用 GNU Screen paste 命令将您的文本粘贴到终端中(Ctrl-a ]除非您更改了转义键)。
  3. 如果文本不以换行符结尾,请按<enter>插入一个。
  4. 最后,按Ctrl-d使pbcopy文本推送到系统剪贴板。

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

然后,您可以像往常一样使用Command-v或等效的菜单选项将文本粘贴到 OS X 中的其他位置。

回答by michalzuber

Finally today I found a solution with mouse:

终于今天我找到了一个鼠标的解决方案:

Hold down Ctrland right clickwith mouse. Copy/paste context menu shows up.

按住Ctrl并用鼠标右键单击。出现复制/粘贴上下文菜单。

Some screens at https://michalzuber.wordpress.com/2015/01/28/gnu-screen-copy-paste-with-mouse/

https://michalzuber.wordpress.com/2015/01/28/gnu-screen-copy-paste-with-mouse/的一些屏幕

回答by kungfuspider

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

有一种更简单、更少手动的方法来做到这一点。在您的屏幕 .rc 文件中,添加以下行:

bindkey -m ' ' eval 'stuff 0' '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.
  1. screen -c path/to/screen/config.rc
  2. 按 Ctrl+A 然后按 Esc 进入复制模式。
  3. 向上滚动文本缓冲区,找到要留下开始标记以进行复制的位置,然后点击空格。
  4. 向下滚动并选择要复制的文本。完成后,再次点击空格。
  5. 文本现在将在您的剪贴板中。

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

编辑:在没有 pbcopy 但有 clipit 的 Linux 上,您可以使用如下:

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

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

回答by CoderX

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+athen |'This is not an i. It is the PIPE sign on your keyboard'

最简单的方法是将屏幕分成两个区域。你可以通过点击CTRL+a然后|'This is not an i. 这是键盘上的 PIPE 标志'

Hit CTRL+athen TABto switch to the second region, CTRL+athen cto create a new session in the second region.

点击CTRL+ athenTAB切换到第二个区域,CTRL+ athen在第二个区域c中创建一个新会话。

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

如果要从 nano 复制并粘贴到终端中,请在左侧区域的 nano 中打开文件,点击CTRL+a然后ESC,滚动到复制位置的起点并点击SPACE,通过滚动到终点并点击来选择文本SPACE再次标记副本。

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

现在,您所要做的就是按CTRL+ athenTAB切换到右侧的区域,然后按CTRL+ athen ]

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.

您的文本将被写出到命令行。请注意,如果您想直接写入文件,您还可以检查硬拷贝选项。

回答by Ryan

Exit your ssh terminal session, if you are currently connected to a server.

如果您当前已连接到服务器,请退出 ssh 终端会话。

If you are using XQuartz on Mac OS and xsel on the server. You should update the XQuartz pasteboard settings by selecting Preferences in the xQuartz application menu.

如果您在 Mac OS 上使用 XQuartz,在服务器上使用 xsel。您应该通过在 xQuartz 应用程序菜单中选择首选项来更新 XQuartz 粘贴板设置。

XQuartz settings:

XQuartz 设置:

enter image description here

在此处输入图片说明

ssh into the remote machine and try run:

ssh 进入远程机器并尝试运行:

xsel -p <<<"THIS IS A TEST".

Press cmd + v and "THIS IS A TEST" should be output.

按 cmd + v 并应输出“这是一个测试”。

回答by CpILL

Since nobody seems to have directly answered the question:

由于似乎没有人直接回答这个问题:

Once you have copied the output you want into your buffer you need to

将所需的输出复制到缓冲区后,您需要

  1. Open a text editor with a new file i.e. vim somefile.txt
  2. Go into edit mode i.e. iin vim
  3. Press Ctrl + athen ]which will dump the contents of the buffer you just filled into the text editor
  1. 使用新文件打开文本编辑器,即 vim somefile.txt
  2. 进入编辑模式,即i在 vim 中
  3. Ctrl + athen]这会将您刚刚填充的缓冲区的内容转储到文本编辑器中

ta-da!

达达!