[lug] Gnome Terminal Dynamically-set title problem

Ron Wright halsaves at gmail.com
Fri Jul 1 09:46:21 MDT 2005


On 6/30/05, Michael J. Hammel <mjhammel at graphics-muse.org> wrote:
> On Thu, 2005-06-30 at 19:45 -0600, Ferdinand Schmid wrote:
> > You can configure it in the Edit Profile -> Title and Command tab to
> > "Dynamically-set title:".  However, this only works for me when I ssh into a
> > very old SuSE Linux machine.  Any of the newer machines must not return the
> > proper status to the shell because my title update fails.
> >
> > So far my google searches remained fruitless.  Any ideas what I need to do get
> > this feature working?
> 
> Most X terminals support escape sequences for this.  I've been doing it
> like this for years in my .bashrc (or kshrc as the case may be):
> 
> if [ "$TERM" = "xterm" ] && [ "$0" = "bash" -o "$0" = "-bash" -o "$0" =
> "/bin/bash" ]
> then
>    ilabel () { echo -n "^[]1;$*^G"; }
>    label () { echo -n "^[]2;$*^G"; }
>    cds () { "cd" $*; eval stripe; }
>    vis () { eval stripe2; "vi" $*; eval stripe;}
>    alias cd=cds
>    alias vi=vis
>    eval stripe
>    # eval ilabel "$USER@$HOSTNAME"
>    eval ilabel "$HOSTNAME"
> fi

If you have bash, then this is a cleaner way:

host=$(uname -n)
if [ "${TERM}" = "xterm" -o "${TERM}" = "xterm-color" ]
then
   if [ -z "${BASH}" ]
   then
      echo "\033]2;${host}\007\033]1;${host}\007"
   else
      export PROMPT_COMMAND=\
      'echo -ne "\033]2;${host}:${PWD}\007\033]1;@${host}:${PWD}\007"'
   fi
fi

Also, for VIM just add "set title" to your .vimrc.  Bash with the
PROMPT_COMMAND set as above will set it back when you exit.

> 
> So when I cd into a directory, the directory gets stuffed into the
> terminal title bar.  And when I vi a file, the filename gets stuffed int
> he title bar (and reset when I exit vi).  Works in gnome-terminal,
> xterm, rxvt, kterm, eterm, and XFCE's Terminal, plus lots of others.
> The if test might need tweaking, but that should be about it.  The ^G is
> a real Ctrl-G.  I can also run "label blah" at any time to put "blah" in
> the title bar.
> 
> --
> Michael J. Hammel           |   We're going to turn this team around 360
> The Graphics Muse           |   degrees.
> mjhammel at graphics-muse.org  |      Jason Kidd, upon his being drafted by
> http://www.graphics-muse.com       the NBA's Dallas Mavericks
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> 

Ron Wright



More information about the LUG mailing list