问题没有得到解决,尽管有一个答案被接受了:,我们正在努力使乔纳的代码工作。
问题:将(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如何在屏幕内使用pbcopy?
发布于 2009-05-03 04:40:42
好的,这是一个螺旋的答案,但它也是一个螺旋的问题,所以至少他们匹配。您可以使用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您可以将其命名为pbcopy_server.sh,生成可执行文件(chmod a+x pbcopy_server.sh),并将其放置在您的路径中,因此您可以在第一次启动计算机时使用nohup pbcopy_server.sh &。
2.任何其他终端(包括屏幕会话中的终端)中的,现在您可以使用cat文件(或者将程序的输出重定向到/tmp/pbCop.管道中,文本将出现在剪贴板中)。
cat file > /tmp/pbcopy.pipe
df -h > /tmp/pbcopy.pipe3.为了使它看起来像你在调用真正的pbcopy,您可以使用一些东西为您做/tmp/pbcopy.pipe猫。
3a.使用zsh函数:
function pbcopy() { cat > /tmp/pbcopy.pipe }3b.或创建一个名为pbcopy的Perl脚本,并将其放在比/usr/bin更早的PATH目录中。
#!/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 <>;发布于 2009-05-29 18:16:53
有一个简单得多的解决方案,就像在http://www.samsarin.com/blog/2008/10/18/copying-gnu-screen-buffer-to-leopard-clipboard/中发现的那样,只使用osascript
在注释中,Andrew Wason提供了此解决方案来复制屏幕缓冲区:
代码在您的.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/pbboxScreen.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发布于 2009-05-14 21:29:55
您可以安装Macport屏幕的旧版本,它似乎解决了这个问题,如本文的注释中所述:
链接到解释如何做的最后一条评论
我已经试过了,屏幕现在在pbcopy上工作得很好!:-)
检查这一步:
$ sudo vi /opt/local/etc/macports/sources.conf
最后,这2行只保留在sources.conf中,不再有:
file:///Users/xxxxx/ports
rsync://rsync.macports.org/release/port/ default$ cd
$ mkdir -p ports/sysutils/ (不创建“屏幕”目录,svn将)$ cd ports/sysutils/
$ svn co -r 45745 http://svn.macports.org/repository/macports/trunk/dports/sysutils/screen$ sudo port install screen (下载屏幕并安装它可能需要一段时间)然后就完成了,只需启动/opt/local/bin/screen即可。
https://stackoverflow.com/questions/816302
复制相似问题