Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a command in GNU Screen to direct standard output to the copy buffer

I've been doing alot of work with files, it's great to copy and past the filenames I want into commands

e.g.

ls | grep proc

$ ls | grep cal
calendar.inc-gen.php

// enter copy mode
$^a y 
// backward search for gen_chg
? cal
// start region
SPC
//goto to end of file by forward search php
php
// done 
ENT
// type command line
$ git rm ^p
// creates
$ git rm calendar.inc-gen.php

I'm aware there are easier ways to do this with a bash script, but often I find myself needed a specialized piece of information from the terminal screen and it would be great to just type

ls | grep cal > To_GNU_SREEN_COPY_:) or something

dennis's solution below works

you may need to set the bufferfile in your .screenrc bufferfile /tmp/screen-exchange

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Here's one way:

echo -n cal* > /tmp/screen-exchange
screen -X readbuf    # or press Ctrl-a <
git rm ^a]           # type "git rm" then press Ctrl-a ]
share|improve this answer
    
it doesn't work for me, but I'll try experimenting around in that area, thanks –  Fire Crow Jul 18 '09 at 4:40
    
It worked mostly as Dennis said. Only small issue is that the echo will include a newline which may or may not cause problems with composing the command line with the paste (^a]). echo -n took care of that. A neat trick I learned today :-) –  njsf Jul 18 '09 at 4:52
    
@njsf: The -n is a good idea. I've edited my answer. Thanks. –  Dennis Williamson Jul 18 '09 at 6:17
    
@Fire Crow: What's happening, specifically? –  Dennis Williamson Jul 18 '09 at 6:18
    
@dennis : it's just not in the gnu screen copy buffer Ctrl-a ] pastes nothing or the copy I made before running these commands, I'm in gentoo linux with gnu screen 4.00.03, I'm guessing it's in the readbuf line, maybe pointing to the wrong file –  Fire Crow Jul 23 '09 at 16:17

The gnu-screen Copy / Scrollback Buffer is located at register .

To send a string to the Copy / Scrollback buffer from a shell within the screen session you can use the register command like so:

screen -X register . 'Hello World'

However, if this command is running from a script, as is likely the case then you will need to specify the screen server name.

screen -S "1234.pts-1.localhost" -X register . 'Hello World'

This command will also pull the value from a shell variable without the need for echo:

x='Hello World'
screen -S "1234.pts-1.localhost" -X register . $x

Specifying the window is not required, however this is how you would do it.

y='Goodbye World'
screen -S "1234.pts-1.localhost" -p 2 -X register . $y
# Walk into the ocean.... fade to black....  roll credits
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.