3

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

Fire Crow
  • 235
  • 2
  • 9

2 Answers2

3

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 ]
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
  • it doesn't work for me, but I'll try experimenting around in that area, thanks – Fire Crow Jul 18 '09 at 04: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 04:52
  • @njsf: The -n is a good idea. I've edited my answer. Thanks. – Dennis Williamson Jul 18 '09 at 06:17
  • @Fire Crow: What's happening, specifically? – Dennis Williamson Jul 18 '09 at 06: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
  • @dennis, IT WORKS!!!!!!!!!!!, I just had to run command from inside screen (Ctrl-:) ":bufferfile /tmp/screen-exchange" first to set that path as the bufferfile, also putting "bufferfile /tmp/screen-exchange" in my .screenrc works – Fire Crow Jul 23 '09 at 16:27
  • Sorry about that. On my system the bufferfile defaults to `/tmp/screen-exchange`. I'm glad you got it working. Looking at the `man` page, your default might be `/usr/tmp/screens/screen-exchange` – Dennis Williamson Jul 23 '09 at 16:41
2

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