Vra

Probleem Nie opgelos hoewel een antwoord aanvaar:. Ons is besig om Jona se kode te werk te kry

Probleem: om die kode van verandering (1) tot (2)

Ek weet die draad . Ek wil in staat wees om die volgende kode binne skerm hardloop

Code (1)

cat ~/.vimrc | pbcopy                   (1)

Code (2)

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

My poging om die probleem op te los: om die volgende kode te sit om .zshrc

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

Ek kry

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

Hoe kan jy pbcopy gebruik binne skerm?

Was dit nuttig?

Oplossing

Goed, dit is 'n afgejakkerd antwoord, maar dit is ook 'n afgejakkerd vraag, so ten minste pas hulle. Jy kan 'n naam van pyp te skep met mkfifo , en dan die opstel van 'n oneindige lus wat lees lêers van die naam van pyp en pype hulle pbcopy (of xsel, xclip, ens.).

1 In 'n terminale wat nie in 'n skerm sessie (hardloop dit slegs een keer):.

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

Wil jy dalk hierdie omskep in 'n dop script soos (dit moet waarskynlik meer robuuste wees)

#!/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

wat jy pbcopy_server.sh kan noem, maak uitvoerbare (chmod a+x pbcopy_server.sh) en sit iewers in jou pad, sodat jy kan sê nohup pbcopy_server.sh & wanneer jy die eerste keer jou masjien te begin.

2. In enige ander terminale (insluitend dié in die skerm sessies) jy kan nou kat lêers (of lei uitset van programme in /tmp/pbcopy.pipe en die teks sal verskyn in die knipbord.

cat file > /tmp/pbcopy.pipe

df -h > /tmp/pbcopy.pipe

3. Maak dit lyk soos jy doen 'n beroep die werklike pbcopy jy kan iets gebruik om die cat'ing doen om /tmp/pbcopy.pipe vir jou.

3a Gebruik 'n zsh funksie:.

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

3b of 'n Perl script met die naam pbcopy en sit dit in 'n gids vroeër in jou PATH as /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 <>;

Ander wenke

Daar is 'n baie makliker oplossing vir net gebruik osascript as gevind word by http://www.samsarin.com/blog/2008/10/18/copying-gnu-screen-buffer-to-leopard-clipboard/

In die kommentaar, Andrew Wason bied hierdie oplossing vir die skerm buffer kopieer:

Code in jou .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'"

Ook die gebruik van osascript, hier is 'n bash script wat die gedrag van pbcopy binne skerm naboots. Verbeterings aan hierdie script is welkom:

Stoor hierdie kode as 'n bash script êrens in jou pad, byvoorbeeld: ~ / 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

Dit blyk in Snow Leopard se weergawe van die GNU skerm vas te stel, selfs al is dit hou dieselfde weergawe 4.00.03 (FAU) 23-Oktober-06.

Alternatiewelik kan jy werk te skerm weergawe 4.01:

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