Monday, August 20, 2012

screen configuration for automatic session names

screen is an immensely useful program, but once you start running multiple sessions at the same time, it gets tricky to find the right one again.  For example, which one was offlineimap again?

 :: whot@salty:~> screen -ls
There are screens on:
    5238.pts-3.salty    (Detached)
    5229.pts-3.salty    (Detached)

The -S argument allows to specify a session name but I couldn't find a configuration to set this automatically. So I've added this little script:

$> cat $HOME/scripts/screen
/usr/bin/screen $([[ ($1 != -*) && ($# > 0) ]] && echo "-S $1") "$@"

Explanation: if called with 1 or more parameters and the first parameter does not start with a dash, replace a call in the form of screen command ... with screen -S command command ...

This results in screen sessions having useful names, allowing for more effective reattaching. And the obligatory, ahem, screenshots: 
:: whot@yabbi:~> screen foo
[detached from]
:: whot@yabbi:~> screen bar
[detached from]
:: whot@yabbi:~> screen -ls
There are screens on:    (Detached)    (Detached)
2 Sockets in /var/run/screen/S-whot.


Leho Kraav said...

Did you write somewhere why you haven't moved to tmux yet?

$ tmux new -s howdy

ctrl-b + s gives a session list by name, indispensible.

OK I admit, I actually have "set -g prefix C-a" :> yes I'm afflicted by my screen history as well


$ tmux attach -t howdy

Peter Hutterer said...

Leho: merely because I wasn't really aware of tmux. Thanks for the hint, I'll have a look.