[NTLUG:Discuss] Re: Bash can put the current command into your xterm title

Steve Baker sjbaker1 at airmail.net
Tue Aug 20 21:42:28 CDT 2002


Lance Simmons wrote:

> The basic idea is simple: you just have to get the escape characters
> right.

I've been using a trick like this for about the last 15 years on various
UNIX/Linux/Solaris/IRIX machines - and my little C program that figures
out which windowing system, which terminal tool and hence which escape
characters to send has grown in to the nastiest mess of a program you've
ever seen.  I probably have a hundred lines of shell scripts, aliases
emacs macro's and other junk that hang around it to make it work.

There *really* needs to be a standard for those escape sequences.  Better
still, a standard library I/O stream (stdbanner or something) to write
this data to the banner when stdout and stderr are redirected somewhere.

FWIW: My favorite thing to put into the title bar is:

      The last twenty characters of the current working directory
...and...
      The name of the machine I'm currently logged into (or rlogged into)
...and...
      The name of the file I'm editing if I'm using 'vi' or 'emacs'.
...or...
      The current user ID if I'm not in an editor.

...separated by two ':' characters.

Some of those things are suprisingly hard to get right.  For example,
if you are sitting in front of a KDE 'Konsole' window on a Linux box
but rlogged into a Solaris machine, my little program is actually
running on the Solaris machine - and realising that it has to send
Konsole-compatible escape sequences whenever you do a 'cd' or 'pushd'
or 'popd' or whatever.  That's managed by some really messy combinations
of 'alias' and passing of shell variables around.  The scheme breaks down
for some really tricky commands - so I have a 'rb' command which refreshes
the banner when it gets confused.

The world needs a better way to do this!

----------------------------- Steve Baker -------------------------------
Mail : <sjbaker1 at airmail.net>   WorkMail: <sjbaker at link.com>
URLs : http://www.sjbaker.org
        http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
        http://prettypoly.sf.net http://freeglut.sf.net
        http://toobular.sf.net   http://lodestone.sf.net






More information about the Discuss mailing list