tags:

views:

194

answers:

1

I have a copy in Screen's clipboard which contains the word Masi aften. I would like to replace it with Bond effectively such that I edit the clipboard directly in Screen's command-mode. I know that I could save the clipboard to /tmp and run the replacement there in Vim, but I want to learn Screen.

I run as I have my data in Screen's clipboard

Ctrl-A : sed s/Masi/Bond/ | [Screen's clipboard]       /// I do not know how to refer to Screen's clipboard by a command other that C-A ]

I get

unknown command sed

How can you run a command to Screen's clipboard in Screen's command mode?

+2  A: 

I don't think screen has any way of running commands on the paste buffer.

One way to do it is to make a bind to save the paste buffer and open a new window in screen that runs a script to modify the buffer. Then make another bind to reload the modified buffer from disk and paste (this can be bound over the normal paste bind).

Add this to screenrc (changing paths):

bind -c screensed s eval "writebuf /pathtoscript/screensed.clipboard" "screen sh /pathtoscript/screensed.sh"
bind -c screensed p eval "readbuf /pathtoscript/screensed.clipboard" "paste ."
bind , command -c screensed

Make a shell script somewhere:

#!/usr/bin/env sh
echo "Enter sed script: "
read sedcommand
sed -i ${sedcommand} /pathtoscript/screensed.clipboard
echo "(Enter to return)"
read something

"ctrl-a , s" in screen will dump the clipboard and make a new window for the sed command to be entered. "ctrl-a , p" will read the clipboard and paste. The pause at the end of the script is to show any errors sed might give.

Yuriy Yashkir
Do you know where Screen stores its clipbeard?
Masi
I think the screen paste buffer is just kept in memory until a "writebuf" command is done. I don't know of any way to make screen automatically write the buffer after copying. I expect that kind of automatic write would be fairly simpl if you're willing to look into the source code.
Yuriy Yashkir
Found this with a quick search: http://snarfed.org/space/synchronizing%20GNU%20screen%27s%20paste%20buffer%20and%20the%20X%20selection , apparently "stuff ' '" will do a copy when in mark mode (odd).Putting this into your screenrc will make screen automatically write to a file when you copy: bindkey -m > eval "stuff ' '" writebuf
Yuriy Yashkir
Did you manage to run Sed in Screen's clipboard? --- Do you mean that your way is to save the buffer first to a file and then run Sed to the file such that you then save the file back to Screen's buffer?
Masi
1) make screen write the buffer, 2) run sed on it, 3) read the buffer back. I don't know of any other way of doing it, but with the right binds you can make it fairly seamless.
Yuriy Yashkir