Hey,

I've generally only run a single screen process on any one host, but
recently I've started to run a couple at home, as I'm no longer running my
IRC sessions from a remote machine. The problem with multiple screen
sessions is that when you want to reconnect to them, you have to provide the
process/socket ID which is garbage to the brain. For instance:

  $ screen -dr
  There are several suitable screens on:
          24349.pts-9.lazarus     (Attached)
          31572.pts-12.lazarus    (Attached)
  Type "screen [-d] -r [pid.]tty.host" to resume one of them.

Not only do they mean nothing, but it's extra work having to specify which
one I want to connect to. So, I started playing around with named sessions.
If you pass the -S <name> parameters, you can reconnect to that session
using screen -dr <name>. Tasty. But that's still too much work for the lazy
admin in my black, charred soul. Enter screen-return!

  #!/bin/sh
  ME=$(basename $0)
  screen -dr $ME || screen -S $ME -p 0 $(find /bin /usr/bin -name $ME -print | head -1)

  * basename $0 returns the filename component of the script itself, so the
    idea is that you create command name symlinks to screen-return; so if I
    had a symlink "mutt" pointing to screen return, ME would be "mutt".

  * The first screen -dr will attempt to reconnect to the screen named after
    "ME" (the command).

  * If it fails (|| means "OR"), the script starts a new screen session
    named after "ME", switches to the first window (-p 0), and runs the real
    "ME" command (currently done by a dumb search on /bin and /usr/bin). You
    can't just run the command, because this script is most likely in your
    path. :-)

So now, when I start a new terminal or log into a host, I just run the
command I care about, and if that means it needs to reconnect to a screen
for me to get it, that's what it does. Rocking! My main uses for this are
apps that I wouldn't run two copies of, such as mutt and irssi.

- Jeff

-- 
GVADEC 2004: Kristiansand, Norway                    http://2004.guadec.org/
 
                              <boc> man i rule
                       <bram> boc: how do you rule?
                            <boc> with authority
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to