Re: Help using eval in screenrc

Michael Grant <mgrant-q2t/[email protected]> Sat, 28 Mar 2020 17:34:11 -0400
Newsgroups gmane.comp.gnu.screen.user
Message-ID <[email protected]>
On Sat, Mar 28, 2020 at 04:20:51PM -0400, dan d. wrote:
> 
> I recently asked how one can stack commands with one keybinding in screenrc
> 
> One poster pointed me to eval, which is surely the solution.  Much googling for examples confirmed it can work.
> 
> But alas I have had no joy trying to modify the examples for my purpose with multiple trial and errow attempts.
> I want to do a keybinding with eval to stack these commands which work now when entered manually:
> 
> 1. enter the command c-a, defined for me as ^F.  I couldn't find in the examples if this a literal ^F or some
> other representation of the command key.
> 
> 2. do a "hardcopy entering h, one example suggests a -X hardcopy works, no joy. wen tried.
> 
> 3.. Enter an already defined keybind with exec which runs a shell script manipulating the hardcopy text file.
> -- 
> Has anyone experience/suggestions for this?
> 
> Many thanks.
> 
> Dan
> XB

First, I have my c-a key bound to c-^.  I don't know who thought c-a
was a reasonable choice since it's often used for the beginning of line
in most shells I use.  c-^ is unused by most everything that I have found.

Add this line to your .screenrc to do this:

    escape ^^^^

I don't know if this will help but I created
for myself a key which repainted the scrollback buffer.

    pastefont on
    defscrollback 2000
    register A "\036[g G$>\000\036:exec /home/mgrant/bin/redraw-screen\015"
    bind ^l process A

Some explanation of register A:

\036 is the ctrl-^ character (which was ctrl-a before using the escape comm=
and above)
[	is the copy command (see https://www.gnu.org/software/screen/manual/html_=
node/Copy.html#Copy)
g	moves to the beginning of the scrollback buffer (see https://www.gnu.org/=
software/screen/manual/html_node/Movement.html#Movement)
<space>	sets the first line to be marked
G	moves to the end of the scrollback buffer
$	writes the marked selection to /tmp/screen-exchange (see https://www.gnu.=
org/software/screen/manual/html_node/Specials.html#Specials)
\000	ends the command <---- THIS MAY ANSWER YOUR QUESTION
\036	is the ctrl-^ again
:	introduces a command (see https://www.gnu.org/software/screen/manual/html=
_node/Colon.html#Colon)
exec	(see https://www.gnu.org/software/screen/manual/html_node/Exec.html#Ex=
ec)
redraw-screen is this command below
\015	is a newline which ends this whole sequence by entering the command

In order to get all of that into a key, I put it in a register and bound a =
key to process that register.

Here is my redraw-screen command:

    #!/usr/bin/perl

    # Use sleep to create a delay so as not to overrun Screen
    use Time::HiRes qw(usleep nanosleep);

    # expects screen dump to already be in /tmp/screen-exchange
    # from the '>' write screen-exchange command in screen
    open(FP,"</tmp/screen-exchange");

    # read screen dump into $a
    @a=3D<FP>;

    for ($i=3D0; $i<@a-1; $i++) {
	print $a[$i];
	usleep(50);
    }
    # special case, if the prompt is the last thing in the dump
    # append a space (you may need to uncomment this)
    #$a[$i] =3D~ s/(\d+])$/\1 /sm;
    print $a[$i]." ";

    # delete the screen dump file
    unlink "/tmp/screen-exchange";

And finally, to use this, you would simply do c-^ c-l and it redraws
the scrollback buffer.  This is extremely useful when you change
screens and change back to a screen and you want to scroll back up.
In my opinion, Screen should do this by default!

And, if anyone else has a better way of redrawing a screen's
scrollback buffer than this, please post!  I spent ages working this
out.  The only thing it does not redraw is the color, though I have
'paste font' enabled.

Hope this helps!

Michael Grant
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEDXVee01gWrPIdWPRwgRAue7sYQMFAl5/wtMACgkQwgRAue7s
YQPCMxAAoQeuZggp/CZKxDaEbROK+ZVsiH55rUaXtUbJiec+Xf86XymSw4FOVSY8
5c9MbBUa2scokOZ9zAVcsGjdcKUO2wpTUkjApToB67JCHqj3erZNmPSqZzPmp0sB
+1uGoqknbGjQ56KBapkff7S7uzxGb5PhLmrDq2rv8dfD0Hlf32o4mAENhi6ue3VQ
nubJKpjL4EpESJXlGCDoCMiOTx6CE+z0b5l1DaRZ9vZ0mQudXl9hWT4sG7xiYTYn
mTHguezP8cXUTwMGha/Q2osXEdUqHow7LOeBZ0vQtdnZMlMEWOmDh67f7hMp3VvD
Z8VQWFUtlu+EspTvxznS42b2LjGMkbLxjkFg2VIJ/TMDwSAlqIJ5CAZPzSKRSPkM
y2iXkuZM+zXPtTwiuofJhvZ9X59ewO1h+vrI0HU7KvJkBFkqtSezmTK+NF8Ao6zi
aRpECVKdj4eQh64e1MMwF4NE/pQ+JtrY1VjJKUcoyV5lI73Cys1TlC76l0+H7Lhs
/O33QC723ZdZbeVrzQLWn7Mve2xG4TRn9rUZIdC6mHphDt9NYyTJOCgYzWpkPkZT
MSV8D0DMb5Tz3i5Z4lKJ1gN6RV/F+JdudPypT55MZG7thjVkvlgG+bRoEaCD3xe/
Zh3JGEtDmjm0x1IYWsMYelAv4OE10+rukvTO9y6mZAlgVWIOvqw=
=r9i/
-----END PGP SIGNATURE-----