Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Benefits of GNU Screen/tmux vs direct terminals
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1959

PostPosted: Sat Jul 25, 2020 9:05 pm    Post subject: Reply with quote

Quote:
I did try it once (not super intensively), and my problem was that I was forgetting that I am in screen session and that there are some other sessions in the same terminal window. So after some time
there were several orphaned screens that I forgot about. So I returned to 'one window - one session' workflow. Perhaps requires some practice.

Just use `screen -DR`
It will forcefully re-attach to an existing session if it exists and start a new one if it doesn't.
Also, screen is super useful with SSH. I like running it as `ssh myuser@remote.host -t screen -DR`, particularly handy when working over an unstable radio link (though wireguard too can circumvent dropping links to some extent - like in before your TCP connection times out).
Back to top
View user's profile Send private message
cboldt
l33t
l33t


Joined: 24 Aug 2005
Posts: 906

PostPosted: Sun Jul 26, 2020 12:40 pm    Post subject: Reply with quote

I use a script called "attach" that will find an existing screen session if one so named exists, otherwise create one with that name.

The script takes advantage of screen ability to open using other than default config file. I only have a few sessions, one for email, one for a handful of occassionally used thinks, mostly alsamixer but also `mc`. The command `attach email` opens a screen session with no split window, Alt-0 is a `tailf` of procmail delivery log, Alt-1 is alpine (started manually), and Alt-2 is a shell. One instance of this runs on the LAN. From any machine I can ssh to the email server and run `attach email` to get that working environment. It runs all the time.

Code:
#!/bin/bash
 
# ~/bin/attach
# Finds screen session and, if it exists, reattaches to it
# If screen session does not exist, start a new one
# When starting a new screen session, use .screenrc-$1 if it exists
 
# alias screen-misc='TERM=xterm screen -x `screen -ls | grep misc-Client | cut -f2`'
 
if [ "$TERM" = "screen" ]; then
        echo You are already in a SCREEN session ...
        echo I will not attach a screen session from within screen
        exit
elif [ "$1" == "" ]; then
        echo You must supply an argument.
        screen -ls
        exit
fi
 
screen -ls | grep "Remove dead screens" && screen -wipe
 
if [ -z "`screen -ls | grep $1-Client`" ]; then
#       echo There is no screen session known as \"$1-Client\"
        if [ -f ~/.screenrc-$1 ]; then
#               echo -ne "\033]0;screen-$1\007"
# Start new screen session with .screenrc-$1 configuration
                exec screen -c .screenrc-$1 -S $1-Client
                exit
        else
#               echo -ne "\033]0;screen-$1\007"
# Start new screen session with .screenrc configuration
                exec screen -S $1-Client
                exit
        fi
else
# Attach to existing screen session
        exec screen -x $1-Client
fi


I also use screen to get an equivalent of multi-tabbed lynx browser, but without the tabs. Alt-1, Alt-2, Alt-3, etc. to jump between instances of lynx.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum