Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running gnome-terminal set to update its title according to terminal commands updating their own titles (default on Fedora 13). When I SSH to somewhere else the title is updated correctly, but then SSH exits and gnome-terminal is indicating that I'm still logged in remotely. This is confusing when trying to navigate around. How do I maintain the behaviour when logging in, and restore the old title when logging out (by default just "Terminal", but better yet display current location)?

share|improve this question
    
Which shell are you using on the local side? – Ignacio Vazquez-Abrams Oct 15 '10 at 9:54
    
Don't have access right now, pretty sure it's bash though - whatever is default for gnome-terminal on Fedora 13. – Sam Brightman Oct 16 '10 at 6:01
up vote 6 down vote accepted

Add the set-title escape sequences to your shell's rc file. For bash v4, this would be:

if [[ $TERM == xterm* ]]; then
    # This puts "user@host workdir" into the titlebar.
    # (look for section "PROMPTING" in bash's manual)
    title='\u@\h \w'

    PS1+="\[\e]0;$title\007\]"
fi

in your ~/.bashrc.


Stop reading here unless you like messing with bash scripts.

The code above is actually a greatly simplified version of my ~/.bashrc snippet:

case $TERM in
[xkE]term*|rxvt*|cygwin)
    title_seq='\e]0;%s\007';;
screen*)
    # only set the "screen"window title
    title_seq='\ek%s\e\\';;
esac

# Very useful for: title syslog && tailf /var/log/syslog
title() { [ "$title_seq" ] && printf "$title_seq" "$*"; }

# Modify the prompt string.
if [ "$title_seq" ]; then
    title='\u@\h \w'
    PS1+="\[$(printf "${title_seq//\\/\\\\}" "$title")\]"
fi

Actually, that was my old ~/.bashrc snippet. Upon discovering PROMPT_DIRTRIM=1 I had to replace the $PS1 modification (the last if statement) with:

update_title() {
    title "$USER@$HOSTNAME ${PWD/#$HOME/~}"
}
PROMPT_COMMAND="update_title"
share|improve this answer
    
Thanks, love it. @Sam-Brightman : Please accept this answer. – vasquez Nov 18 '11 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .