GNU Screen and kitty/putty integration

Hi All,

Today I am going to share a small script and some steps which can increase the functionality of putty/kitty/mobaxterm along with GNU Screen .

Now before moving ahead , let me tell you , though I like GNU Screen , but one of the constraints of using it is the clipboard copy using mouse. Now lot of times we need to copy-paste from our local system to remote hosts which are connected using ssh. Now during that time, GNU screen is a real problem, as the buffer shared by all the tabs opened by one screen session are shared, mouse scrolling gets messed up so many time.

One thing here , yes we can enable mouse scrolling in GNU screen using the following command set on your .screenrc file : "termcapinfo xterm* ti@:te@ " . What it does is the first one enables the scrolling for xterm and another good option "altscreen on" it clears the screen when your close vim , instead of keeping the text from vim after you closed it .

But the problem is then how you will maintain multiple screen session, as manually you have to do screen -ls each time when you open a terminal and attaching the screen . Instead of that I have automated it using a small script which we can call from either remote host .bashrc , or from ssh command line during logging in .

x=`screen -ls|grep Det|grep -v grep|awk '{print $1}'|head -1`;

count=`screen -ls|grep Att|grep -v grep|wc -l`

$count=$(($count+1))

name="work"$count

if [[ $x ]];then screen -r $x;else screen -S $name;fi

save it in your home directory and source it from .bashrc or call it during logging in through ssh.

What it does is simple , it checks all the screen session detached (if any) , and finds the top one and then we check number of attached connections , and then create new name for the session using that count appended after the name .

It will look like :

#screen -ls

There are screens on:

    16422.work1  (Attached)

    14565.work   (Attached)

Also when we will close the ssh session , instead of closing the Screen , then during opening the tab/new ssh session it will get reconnected . So you can stop worrying about your ssh session termination can cause killing your on going work.

Once some ssh sessions are closed , "screen -ls" is showing like :

There are screens on:

    16422.work1  (Attached)

    16454.work2  (Detached)

    14565.work   (Detached)

Now once I connect one new ssh to the same remote machine:

There are screens on:

    16422.work1  (Attached)

    16454.work2  (Attached)

    14565.work   (Detached)

This is the ssh command I am using :

ssh user_me@my_remote -t 'source .profile;source .bashrc;source mymoba.sh'

Here if I type exit, I come out of the screen,as well as ssh session. But if I terminate the putty/ssh session the screen session is still up. For putty use it on ssh -> remote command .



To view or add a comment, sign in

More articles by Souradeep Chakrabarti

Others also viewed

Explore content categories