[ Content | View menu ]

More on screen

Written on February 7, 2007

While I don’t have a screen for a graphical user environment (like X), I do have screen for the terminal, and it rocks.

Here’s how I use it; I have four primary email accounts, each with their own .muttrc. I open a screen session for each account, plus one session as a scratch pad, for the variety of non-mail activities that I do each day. (If you’re thinking that one session for all non-mail activities is too few, you’d be right most of the time, but I have a solution for that too.) I start all of these sessions by calling screen with a special config file, which I call .myscreenrc, to separate it from the regular .screenrc. It looks like this:

autodetach on
shell -$SHELL
screen -t scratch
screen -t uoft u
screen -t nerd n
screen -t witteman w
screen -t woolgathering wg

The -t option givens me a title for each session within screen – which helps me keep everything straight. I call this with a line in my .xinitrc, like so:

sleep 1 && urxvt -geometry 80x56+0+0 -e screen -c .myscreenrc &

The delay helps it come up after my backdrop is drawn, so I don’t have a blank behind my transparent terminal.

All of this is now nicely set up, and I am in mutt (the last email account). I hop between instances in three ways: Ctrl-a " for a list of sessions to scroll through, Ctrl-a ' and the number of the session I want to be in or Ctrl-a n or Ctrl-a p for the next and previous session. If I need a fresh session, it’s as easy as Ctrl-a c.

There are a couple of problems with this setup. The mutt sessions only lasts as long as mutt is open, so if my fingers, from long training, close mutt, then I lose that session as well, and I have to start it afresh. The solution, rather than training my fingers, was to prevent mutt from closing. I remapped q in the browser and index modes to be the equivalent of c?, which means that I can only close mutt from the pager by hitting x. Fine by me, and it lets me have long-lived sessions.

Now, whether I am sitting at my machine or ssh-ing in from work, I have all the same things at my disposal, and I can comfortably leave aspects of my work open when changing locations. If I have left my sessions running at home, I simply call screen -x when at work, and I am in my familiar environment. If I have detached at home then screen -r is the right call.

However, if I have detached at home and stopped my X session, I run into the other problem. When I started screen via my .xinitrc I also set the $DISPLAY variable in each session. As such, when I am logged in remotely without X running, certain programs throw errors because I am not able to reach the X session. The sidestep for this is to unset DISPLAY if I am going to be using programs that care about that variable, most notably vim.

It sounds like work, but it is actually extremely sweet, and really easy.

Filed in: blog,config.

Comments closed