无法在屏幕内使用 pbcopy -clipboard

发布于 2024-07-18 06:04:18 字数 799 浏览 11 评论 0 原文

尽管接受了一个答案,但问题尚未解决:我们正在努力让 Jonah 的代码正常工作。

问题:将(1)的代码更改为(2)

我知道线程。 我希望能够在屏幕内运行以下代码

代码 (1)

cat ~/.vimrc | pbcopy                   (1)

代码 (2)

cat ~/.vimrc > /tmp/pbcopy.pipe         (2)

我尝试解决问题: 将以下代码放入 .zshrc

function pbcopy() { "(cat \"$1\")"  > /tmp/pbcopy.pipe } 

我得到

cat masi | pbcopy          
pbcopy: command not found: (cat "")
cat: masi: No such file or directory

How can you use pbcopy inside Screen?

Problem Not solved although one answer was accepted: We are working to get Jonah's code to work.

Problem: to change the code of (1) to (2)

I know the thread. I want to be able to run the following code inside Screen

Code (1)

cat ~/.vimrc | pbcopy                   (1)

Code (2)

cat ~/.vimrc > /tmp/pbcopy.pipe         (2)

My attempt to solve the problem:
to put the following code to .zshrc

function pbcopy() { "(cat \"$1\")"  > /tmp/pbcopy.pipe } 

I get

cat masi | pbcopy          
pbcopy: command not found: (cat "")
cat: masi: No such file or directory

How can you use pbcopy inside Screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云胡 2024-07-25 06:04:19

有一个更简单的解决方案,只需使用 osascript,如 http://www.samsarin.com/blog/2008/10/18/copying-gnu-screen-buffer-to-leopard-clipboard/

在评论中,安德鲁·沃森提供了复制屏幕缓冲区的解决方案:

.screenrc 中的代码

# binds C-a b to copy the contents of your last screen copy to the MacOSX pasteboard
bind b eval "writebuf /tmp/screen-pbcopy" "exec /usr/bin/osascript -e 'tell application \"System Events\"' -e 'set the clipboard to (read posix file \"/tmp/screen-pbcopy\" as text)' -e 'end tell'"

同样使用 osascript,这里有一个 bash 脚本,它模拟屏幕内 pbcopy 的行为。 欢迎对此脚本进行改进:

将此代码保存为路径中某处的 bash 脚本,例如:~/bin/pbcopyScreen.bash

#!/bin/bash

# saves all standard input to a file
cat > /tmp/screen_pbcopy_kludge_buffer

# uses osascript to set the MacOSX pastebaord to the contents of the file
/usr/bin/osascript -e 'tell application "System Events"' -e 'set the clipboard to (read posix file "/tmp/screen_pbcopy_kludge_buffer" as text)' -e 'end tell'

rm /tmp/screen_pbcopy_kludge_buffer

There is a much easier solution to just use osascript as found at http://www.samsarin.com/blog/2008/10/18/copying-gnu-screen-buffer-to-leopard-clipboard/

In the comments, Andrew Wason provides this solution to copy the screen buffer:

Code in your .screenrc

# binds C-a b to copy the contents of your last screen copy to the MacOSX pasteboard
bind b eval "writebuf /tmp/screen-pbcopy" "exec /usr/bin/osascript -e 'tell application \"System Events\"' -e 'set the clipboard to (read posix file \"/tmp/screen-pbcopy\" as text)' -e 'end tell'"

Also using osascript, here's a bash script which emulates the behavior of pbcopy within screen. Improvements to this script are welcome:

Save this code as a bash script somewhere in your path, example: ~/bin/pbcopyScreen.bash

#!/bin/bash

# saves all standard input to a file
cat > /tmp/screen_pbcopy_kludge_buffer

# uses osascript to set the MacOSX pastebaord to the contents of the file
/usr/bin/osascript -e 'tell application "System Events"' -e 'set the clipboard to (read posix file "/tmp/screen_pbcopy_kludge_buffer" as text)' -e 'end tell'

rm /tmp/screen_pbcopy_kludge_buffer
萌能量女王 2024-07-25 06:04:19

您可以安装旧版本的 Macport 屏幕,这似乎可以解决此问题,如本文评论中所述:
链接到最后一条评论解释如何做

我自己尝试过,屏幕现在使用 pbcopy 工作得很好! :-)

检查该步骤:

  1. 使用其 DMG 文件安装 Macport。 Leopard 的 DMG

  2. 启动新终端
    $ sudo vi /opt/local/etc/macports/sources.conf
    最后这两行只保留在sources.conf中,不再存在:

    文件:///Users/xxxxx/ports
    rsync://rsync.macports.org/release/ports/ [默认]

  3. $ cd
    $ mkdir -p ports/sysutils/
    (不要创建“screen”目录,svn 会)

  4. $ cd ports/sysutils/
    $ svn co -r 45745 http://svn.macports.org/repository/macports/trunk/dports/sysutils/screen

  5. 签出后:

    $ cd $HOME/ports
    $ 端口索引
    在 /Users/keugaerg/ports 中创建软件索引
    添加端口 sysutils/screen

    解析的端口总数:1  
      成功解析端口:1     
      端口失败:0 
      
  6. $ sudo port install screen
    (下载屏幕并构建它可能需要一段时间)

然后就完成了,只需启动 /opt/local/bin/screen 。

You may install an older version of Macport's screen which seems to solve this issue, as stated in comments of this article:
link to the last comment explaining how to do

I've tried myself and screen works very fine now with pbcopy ! :-)

Check that step:

  1. Install Macport using its DMG file. Leopard's DMG

  2. Launch a new Terminal and
    $ sudo vi /opt/local/etc/macports/sources.conf
    finally those 2 lines only remains in sources.conf, no more:

    file:///Users/xxxxx/ports
    rsync://rsync.macports.org/release/ports/ [default]

  3. $ cd
    $ mkdir -p ports/sysutils/
    (do not create a "screen" directory, svn will)

  4. $ cd ports/sysutils/
    $ svn co -r 45745 http://svn.macports.org/repository/macports/trunk/dports/sysutils/screen

  5. Once check out:

    $ cd $HOME/ports
    $ portindex
    Creating software index in /Users/keugaerg/ports
    Adding port sysutils/screen

    Total number of ports parsed:   1 
    Ports successfully parsed:  1    
    Ports failed:           0
    
  6. $ sudo port install screen
    (may take a while as downloading screen and buidling it)

Then it's done, just have to launch /opt/local/bin/screen .

七月上 2024-07-25 06:04:19

尽管 Snow Leopard 版本的 GNU Screen 保持相同的版本号 4.00.03 (FAU) 2006 年 10 月 23 日,但该问题似乎已得到修复。

或者,您可以更新到 Screen 版本 4.01:

git clone git://git.savannah.gnu.org/screen.git

This appears to be fixed in Snow Leopard's version of GNU Screen even though it keeps the same version number 4.00.03 (FAU) 23-Oct-06.

Alternatively you can update to Screen version 4.01:

git clone git://git.savannah.gnu.org/screen.git
梦里泪两行 2024-07-25 06:04:18

好吧,这是一个奇怪的答案,但这也是一个奇怪的问题,所以至少它们匹配。 您可以使用 mkfifo 创建命名管道,然后设置一个无限循环,从命名管道读取文件并将它们通过管道传输到 pbcopy(或 xsel、xclip 等)。

1. 在不在屏幕会话中的终端中(仅运行一次):

/usr/bin/mkfifo /tmp/pbcopy.pipe
while true; do /bin/cat /tmp/pbcopy.pipe | /usr/bin/pbcopy; done

您可能希望将其转换为 shell 脚本(这可能应该更强大),

#!/bin/bash

if [[ -e /tmp/pbcopy.pipe ]]; then
    echo "it looks like I am already running"
    echo "remove /tmp/pbcopy.pipe if you are certain I am not"
    exit 1
fi

while true; do
    /bin/cat /tmp/pbcopy.pipe | /usr/bin/pbcopy
done

您可以将其命名为 < code>pbcopy_server.sh,使可执行文件 (chmod a+x pbcopy_server.sh) 并放在路径中的某个位置,这样你就可以说 nohup pbcopy_server.sh & 当您第一次启动机器时。

2. 在任何其他终端(包括屏幕会话中的终端)中,您现在可以 cat 文件(或将程序输出重定向到 /tmp/pbcopy.pipe,文本将显示在剪贴板中。

cat file > /tmp/pbcopy.pipe

df -h > /tmp/pbcopy.pipe

3.为了让它看起来像你正在调用真正的pbcopy,你可以使用一些东西来为你进行/tmp/pbcopy.pipe的cat'ing .

3a. 使用 zsh 函数:

function pbcopy() { cat > /tmp/pbcopy.pipe }

3b. 或者创建一个名为 pbcopy 的 Perl 脚本并将其放入PATH 中比 /usr/bin 更早的目录:

#!/usr/bin/perl

use strict;
use warnings;

open my $out, ">", "/tmp/pbcopy.pipe"
   or die "could not open pipe to pbcopy: $!\n";

print $out $_ while <>;

Alright, this is a screwy answer, but it is also a screwy question, so at least they match. You can create a named pipe with mkfifo, and then setup an infinite loop that reads files from the named pipe and pipes them to pbcopy (or xsel, xclip, etc.).

1. In a terminal which is NOT in a screen session (run this only once):

/usr/bin/mkfifo /tmp/pbcopy.pipe
while true; do /bin/cat /tmp/pbcopy.pipe | /usr/bin/pbcopy; done

You may want to turn this into a shell script like (this probably should be more robust)

#!/bin/bash

if [[ -e /tmp/pbcopy.pipe ]]; then
    echo "it looks like I am already running"
    echo "remove /tmp/pbcopy.pipe if you are certain I am not"
    exit 1
fi

while true; do
    /bin/cat /tmp/pbcopy.pipe | /usr/bin/pbcopy
done

which you can name pbcopy_server.sh, make executable (chmod a+x pbcopy_server.sh) and put somewhere in your path, so you can say nohup pbcopy_server.sh & when you first start your machine.

2. In any other terminal (including those in screen sessions) you can now cat files (or redirect output of programs into /tmp/pbcopy.pipe and the text will appear in the clipboard.

cat file > /tmp/pbcopy.pipe

df -h > /tmp/pbcopy.pipe

3. To make it look like you are calling the real pbcopy you can use something to do the cat'ing to /tmp/pbcopy.pipe for you.

3a. Use a zsh function:

function pbcopy() { cat > /tmp/pbcopy.pipe }

3b. Or create a Perl script named pbcopy and put it in a directory earlier in your PATH than /usr/bin:

#!/usr/bin/perl

use strict;
use warnings;

open my $out, ">", "/tmp/pbcopy.pipe"
   or die "could not open pipe to pbcopy: $!\n";

print $out $_ while <>;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文