You are not logged in.

#1 2008-04-10 21:04:51

blu3ness
Member
From: Edmonton, Canada
Registered: 2007-12-28
Posts: 169

screen friendly .bashrc profile

Goal: trying to shortcut a lot of the routine stuff that I do with screen etc. Basically, when starting a new terminal, I want to start a screen session if there hasn't been one, if there is already screen sessions running, i want to reattach to detached ones first (the oldest first), if all of screens are already attached, then I would want to do nothing and just make the window a normal terminal.

Here's what I've came up with, it works, but it is certainly messy... I'm wondering if there's any other way to do it.

t=`pgrep '^screen'`

if [ $? -gt 0 ]; then
  screen
else
  screen -list | grep "(Detached)" -q
  if [ $? -eq 0 ]; then
    socket=`screen -list | sort -r | grep '(Detached)' -m 1 | cut -d '.' -f 1 | sed 's/\t//'`
    screen -r $socket
  fi
fi

Last edited by blu3ness (2008-04-11 01:05:23)


Archlinux on Compaq Presario v5000 laptop smile

Offline

#2 2008-04-10 23:05:07

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Re: screen friendly .bashrc profile

Isn't 'screen -D -R' doing exactly that? ('man screen')

Offline

#3 2008-04-10 23:28:18

blu3ness
Member
From: Edmonton, Canada
Registered: 2007-12-28
Posts: 169

Re: screen friendly .bashrc profile

Not entirely true, I tried screen -D -R. For example, if I create a new bash session inside screen with ^a c, then the terminal would crash.

screen -D -R also allows for one terminal open at a time...

My idealized behavior would be when starting the terminal, if there's already a session attached, do nothing, if there's no screen sessions running, start one. If there's screen sessions detached, attach to the oldest session available.

yikes

Last edited by blu3ness (2008-04-10 23:31:36)


Archlinux on Compaq Presario v5000 laptop smile

Offline

#4 2008-04-10 23:33:51

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Re: screen friendly .bashrc profile

Ah, it wasn't clear to me from the original post that you want to run this from .bashrc.

Offline

#5 2008-04-11 00:01:21

blu3ness
Member
From: Edmonton, Canada
Registered: 2007-12-28
Posts: 169

Re: screen friendly .bashrc profile

ya, apologies for being confusing...


Archlinux on Compaq Presario v5000 laptop smile

Offline

Board footer

Powered by FluxBB