屏幕内无法使用pbcopy -clipboard [英] Unable to have pbcopy -clipboard inside Screen

查看:327
本文介绍了屏幕内无法使用pbcopy -clipboard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题虽然已被接受,但仍未解决:我们正在努力使乔纳的代码生效.

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

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

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

我知道线程.我希望能够在Screen内运行以下代码

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

代码(1)

cat ~/.vimrc | pbcopy                   (1)

代码(2)

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

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

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

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

我知道

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

如何在屏幕内使用pbcopy?

推荐答案

好的,这是一个棘手的问题,但这也是一个棘手的问题,因此至少它们是匹配的.您可以使用 mkfifo 创建命名管道,然后设置一个无限循环,从命名管道读取文件并将其通过管道传输到pbcopy(或xselxclip等).

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..在不在屏幕会话中的终端中(仅运行一次):

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

您可能希望将其变成一个shell脚本,例如(这可能会更健壮)

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

,您可以将其命名为pbcopy_server.sh,使其成为可执行文件(chmod a+x pbcopy_server.sh),并将其放置在路径中的某个位置,以便您在首次启动计算机时可以说nohup pbcopy_server.sh &.

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..现在,在任何其他终端(包括屏幕会话中的终端)中,您都可以编入文件(或将程序的输出重定向到/tmp/pbcopy.pipe中,文本将显示在剪贴板中).

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..要使它看起来像您在呼叫真正的pbcopy,您可以使用某些方法来为您提供/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..使用zsh函数:

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

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

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 <>;

这篇关于屏幕内无法使用pbcopy -clipboard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆