12
Apr

Musings on Configuring Screen

Posted on April 12, 2011 by justin

So I started using screen a while back, and it was pretty useful. Being able to leave off whatever I'm working on from work/uni, and get straight back into it from home was a godsend.

But there was a problem. By default, screen doesn't really make a lot of information easily accessible. So I did some research, and pieced together bits and pieces from various screenrc examples, and had the following configuration:


# Get rid of startup message.
startup_message off

#change the hardstatus settings to give an window list at the bottom of the
#screen, with the time and date and with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{g}(%n*%f%t%?(%u)%?)%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'

And for a while, all was good. Thing is, my config, as it currently stood, didn't propagate to the window title in gnome's terminal. Whatever the title was set to when screen started is how it stayed. So I set out to find out a cause, and a remedy. Surely SOMEBODY out there has wanted a useful window title combined with an informative status bar.

After much fumbling and false starts, it turns out there are two parts to the solution: First, screenrc - that hardstatus alwayslastline part? That stops the hardstatus being displayed in the terminal's title. We remove that line, and instead of hardstatus string, we use caption always. Then we can use the hardstatus to set the window title. My new screenrc:


# special xterm hardstatus: use the window title.
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'
# Set the window title to something useful.
hardstatus string "[screen %n%?: %t%?] %h"
# display our status bar, time, highlighted window, blah blah
caption always '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{g}(%n*%f%t%?(%u)%?)%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'

Screen also expects slightly different escape characters for $PROMPT_COMMAND, so we add this (or something similar) to .bashrc:


# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
screen)
    PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}: ${PWD/$HOME/~}\033\\"'
    ;;
*)
    ;;
esac

Maybe my google-fu has just failed me, but I'm surprised at how hard the information I needed for this was to find, and most of the solution came from a two year old ubuntu bug report for screen-profiles, whatever that is.

Comments

0 comments have been posted.

Post a comment