You are not logged in.

#1 2009-10-21 15:48:02

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

A good way to use screen in varying situations

Anyone who uses GNU/screen knows how awesome it is.  I use it mainly in two situations:

  when i have one terminal connection (ssh) and want to multitask
  when i have a process that i never want to lose (rtorrent, irssi) while logging in/out playing with X etc.

Yesterday, i came up with a pretty sweet way (i think) of using screen for both of these situations without

  changing current habits (what commands i use day to day)
  affecting current keybinds
  using any crazy complicated scripts

I thought i'd share this with you guys in case anyone else can find it useful.

basically i set up one main ~/.screenrc which defines all my screen options (shell, term, hardstatus, etc).  then i have separate "screenrc_extension" files that only define what tabs to load when screen starts.  i then choose which "screenrc_extension" by use of environment variables

> grep ^source .screenrc
source "$SCREEN_CONF_DIR/$SCREEN_CONF"

> echo $SCREEN_CONF_DIR/$SCREEN_CONF
/home/patrick/.screen/configs/main

> cat .screen/configs/main
# example: screen -t [name] [command]
screen -t mail mutt
screen -t music ncmpcpp
#screen -t calendar wyrd

so here you can (hopefully) see that when i run screen in a clean environment it uses the two exported environment variables to call .screen/configs/main and load the tabs i want 90% of the time.

everything else happens in ~/.bashrc:

# dynamically choose which tabs load in screen
export SCREEN_CONF_DIR="$HOME/.screen/configs"
export SCREEN_CONF="main"

alias rtorrent='SCREEN_CONF=rtorrent screen -S rtorrent -D -R rtorrent'
alias irssi='SCREEN_CONF=irssi screen -S irssi -D -R irssi'

the aliases are key.

> SCREEN_CONF=irssi cat $SCREEN_CONF_DIR/$SCREEN_CONF
# example screen -t [name] [command]
screen -t irc irssi

> SCREEN_CONF=rtorrent cat $SCREEN_CONF_DIR/$SCREEN_CONF
# example: screen -t [name] [command]
screen -t torrents rtorrent

so when i type 'rtorrent' the alias will set the environment variable so the right 'screenrc_extension' is used, re attach any running rtorrent-screens here and now, or create one if needed.  the -S names the session so that any subsequent -D -Rs can find and reattach it explicitly.

and the same thing happens for 'irssi' (or any other app you'd want to use with this approach).

so i can use the same three commands (screen, rtorrent, irssi) just as always and i get this super-convenient behavior.

Offline

#2 2009-10-22 11:14:59

strankan
Member
From: Sundsvall - Sweden
Registered: 2006-11-08
Posts: 97

Re: A good way to use screen in varying situations

Awesome! Will definitely give this a go tonight. smile

Offline

#3 2009-10-22 12:51:18

japetto
Member
From: Chicago, IL US
Registered: 2006-07-02
Posts: 183

Re: A good way to use screen in varying situations

Looks cool.  I use screen pretty much the same way you do, so your idea fits nicely wink

Offline

#4 2009-12-23 01:11:16

Archangel-13
Member
From: The sunshine city.
Registered: 2006-07-23
Posts: 7
Website

Re: A good way to use screen in varying situations

Thanks for posting this, I think this will help me get in to using screen regularly.

Last edited by Archangel-13 (2009-12-23 01:11:45)

Offline

Board footer

Powered by FluxBB