I realized the server I was SSHing into at WebFaction was doing a nice
thing -- my screen session was putting my present working directory (pwd) in
the title bar of my Ubuntu terminal. This is especially great because I
prefer a PS='\$ ' -- a very minimal Bash prompt.
WebFaction runs Red Hat, so it took a while to figure out what they were doing
so I could make the same thing happen on my own Ubuntu servers. GNU Screen
configuration is not exactly straightforward, and I got quite a bit mixed up by
all of the hardstatus commands and escape characters. I eventually figured out
the key bit lies in adding a few lines to /etc/bash.bashrc. They could go in
~/.bashrc, but there's a spot for it in the system-wide file already --
I'll just paste the relevant section right here:
# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# 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}\007"'
;;
# special escaping for Screen
screen)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME}:${PWD}\033\\"'
;;
*)
;;
esac
As the first line says, this section is commented out by default. I've
uncommented it and added the three lines starting with screen). These lines
were in the /etc/bashrc at WebFaction (possibly the default Red Hat
configuration?). This serverfault question also pointed me in this
direction.
Interestingly, when I googled "screen prompt_command" the first hit was
this old Debian bug -- looks like a bad solution that went nowhere.
The Screen manual suggests a similar value for PROMPT_COMMAND in its
section on Title Prompts, but neither worked for me.
The /etc/screenrc at WebFaction also includes the following line:
hardstatus string "[screen %n%?: %t%?] %h"
I like this because it shows your Screen window number, but I usually don't title my Screen windows, so I squeezed it down to this:
hardstatus string "[%n] %h"
Pleasant!