screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: hardstatus and putty scrolling


From: Michael Grant
Subject: RE: hardstatus and putty scrolling
Date: Fri, 28 Aug 2020 21:05:04 +0100

> Would you mind sharing your .screenrc? I feel like I could learn a lot from it. Or if you have a dotfiles repo on github that would be fantastic too.

 

Sure.  I don’t have them in a public repo.  If anything isn’t clear, please ask.  Hope this is interesting/helpful to someone!

 

I almost always have a KiTTY (which is a fork of PuTTY) ssh window open to my servers.  I have a desktop and laptop which I work from interchangeably.  I like being able to just pop open my laptop and continue where I was without having to mess around ssh’ing in.  It’s “always on”.  Second thing I do a lot is flip around between 4 screens: 3 shells and an emacs.  I bound F9 to F12 to these 4 screens for easy.  I use Ctrl-^ Ctrl-L to repaint the scrollback buffer.

 

I start Screen from my .bash_login script which looks for currently running screens.  This is reminiscent of the old Tops-20 when it would ask you to reattach to a detached tree (This message may not be exactly the same as Tops-20, please forgive me).

 

.bash_login:

screen -wipe

# Get list of screens available to re-attach to

a=`screen -ls | awk '/pts/ { print $1 }'`

 

if [ "$a" ]; then

    set $a

    if [ $# = 1 ]; then

        # Single screen running

        if [ "$AUTOLOGIN" ]; then

            exec screen -U -xRR

        fi

        read -n1 -r -p"--Attach Your Detached Tree-- (y/n) [space=y]" && [[ ("$REPLY" = "y") || ("$REPLY" = " ") || ("$REPLY" = "0") ]] && exec screen -U -xRR

    else

        # Multiple screens running

        read -n1 -r -p"--Attach A Detached Tree- (number) [space=1]-"

        echo got $REPLY

        if [[ "$REPLY" = " " ]]; then REPLY=1; fi

        if [[ $REPLY =~ [0-9] ]]; then

            b=`echo $a | awk 'NF='$REPLY' { print $0 }'`

            exec screen -U -x -r $b

        fi

    fi

fi

# Screen not running

echo "type 'screen' to start screen"

 

This needs some explanation of the auto-login, auto-starting of screen stuff.  In /etc/ssh/sshd_config I have this to allow me to pass this env variable:

 

AcceptEnv AUTOLOGIN

 

At some point, I got tired of hitting space each time I logged in so I added an this environment variable to bypass that.  AUTOLOGIN = 1 is set in KiTTY’s Connection->Data->Environment variables section (this variable is my own flag, not part of anything else).  KiTTY allows auto-reconnect (Connection->Reconnect options), which works well with this setup.  This variable is simply telling my .bash_login script that I enabled KiTTY’s auto reconnect feature.  The bash_login script above, if it sees AUTOLOGIN set to something, it bypasses asking the question and just restarts screen.  This is really just a safety in case something is messed up.  I should still be able to log into my server by unsetting this variable and bypassing automatically starting screen.  Trust me, it’s saved me plenty of times!

 

My .screenrc:

 

# Set the Attention character to Ctrl-^ because this is generally not used.  Ctrl-A is used for beginning of the line in shell and emacs.

escape ^^^^

startup_message off

vbell off

multiuser on

fit

 

pastefont on

defscrollback 10000

 

# fix delete key

bindkey -k kD stuff "^?"

bindkey "\033[3~" stuff "^?"

 

# f9,f10,f11,f12 selects window 3,0,1,2

# (f11 = shift-f1, f12 = shift-f2)

bindkey -k k8 select 0

bindkey -k k9 select 1

bindkey -k k; select 2

bindkey -k F1 select 3

bindkey -k F2 select 4

# same thing but for Sun keyboard

bindkey "\033[231z" select 0

bindkey "\033[232z" select 1

bindkey "\033[233z" select 2

bindkey "\033[192z" select 3

bindkey "\033[193z" select 4

 

#markkeys "h=^B:j=^P:k=^N:l=^F:$=^E"

 

# This script “repaints” the scrollback buffer.  Ctrl-^ Ctrl-L writes the scrollback buffer to

# a temp file and then cats it back out.  Doesn’t save the coloring but best I could do.

register A "\036[g G$>\000\036:exec /home/mgrant/bin/redraw-screen\015"

bind ^l process A

 

# \036 is the ctrl-^ character (which was ctrl-a before using the escape command 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#Exec)

# redraw-screen is this command below

# \015  is a newline which ends this whole sequence by entering the command

 

 

# so the current directory, some tabs and the server time can be put in the status line

hardstatus alwayslastline

 

# trused users on my system so that we can share a screen

acladd friend1,friend2

 

# My hard status line is: machine-name [load] tabs | datetime

# The current window’s name is inversed so it looks like a tab, it’s the same color as the background of the ssh window

hardstatus string "%{= KW}%H %{= Kk}[%l]%{-} %{= Kw}|%{-} %-Lw%{= kW} %n%f %t %{-}%+Lw | %{= KR}%u%{-} %=%Y-%M-%d %0c"

#

# http://www.gnu.org/software/screen/manual/html_node/String-Escapes.html

#

# %{= KW} : set colors to bright white text (W) on grey background (K) and keep current text styles (=)

# %H      : hostname

# [       : opening bracket character

# %l      : print load

# ]       : closing bracket character

# %{= Kw} : set colors to white text (w) on grey background (K) and keep current text styles (=)

# |       : bar character

# ${-}    : restore colors to previous colors / undo last color change

# list of windows with active window in black:

#   %-Lw    : list windows before current window (L [optional] = "include flags")

#   %{= bW} : set colors to bright white (W) on black (k) and keep current text styles (=)

#   %f      : window flags (see http://aperiodic.net/screen/window_flags)

#   %t      : window title

#   %{-}    : restore colors to previous colors / undo last color change

#   %+Lw    : list windows after current window (L [optional] = "include flags")

# |       : bar character

# %{= KR} : set the colors to bright red text (R) on grey background (K) and keep current text styles (=)

# %u      : list other users of this window

# %{-}    : restore colors to previous colors / undo last color change

# %=      : expand to fill all space (used here to make remaining content flush right)

# %Y      : current year

# -       : hyphen character

# %m      : current month (0-padded; %M for "Jan" etc.)

# -       : hyphen character

# %d      : current date (0-padded)

# %c      : current time (12-hr is %C; 24-hr is %c)

# %a      : am/pm (lowercase; uppercase is %A)

 

# Start 3 shells and an emacs which I flip around using F9 to F12.

# F9 = shell 1

# F10 = shell 2

# F11 = shell 3

# F12 = emacs

screen 1

screen 2

screen 3

screen 4 emacs

 

/home/mgrant/bin/redraw-screen:

#!/usr/bin/perl

 

use Time::HiRes qw(usleep nanosleep);

 

# expects screen dump to already be in /tmp/screen-exchange

# from the '>' write screen-exchange command in screen

# See screen(1) man page “C-a <” or search for ‘screen-exchange’.

open(FP,"</tmp/screen-exchange");

 

# read screen dump into $a

@a=<FP>;

 

# print out lines not too fast or it messes things up

for ($i=0; $i<@a-1; $i++) {

    print $a[$i];

    usleep(50);

}

# special case, if the prompt is the last thing in the dump

# append a space

#$a[$i] =~ s/(\d+])$/\1 /sm;

print $a[$i]." ";

 

# delete the screen dump file

unlink "/tmp/screen-exchange";


reply via email to

[Prev in Thread] Current Thread [Next in Thread]