« When adcustomizer.sh may not work.. | Main | Do I need permission to make ssh keys work? »

Setting titles on Xterm windows

One of the frequently asked questions in our line of work is how to set the titles of Xterm windows. Especially when we have so many xterm windows

xterms without titles.GIF:

In the above picture, Can you tell which user, machine and directory in which the following sessions are? There are only two options: either look at each icon manually or remember it.

What if you could influence the titles of each xterm window? Good news is, we can.

The answer is available freely on the internet: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html

If we add this to $HOME/.kshrc (assuming KSH is the shell being used), the information that is constant throughout the lifetime of the shell.

echo "\033]0;${USER}@${HOSTNAME}\007"

This is how it will look after this is done.

xterms with titles.GIF:

PS: The hostnames are totally fictional and do not represent any real server names

A Better method - Thanks Laurent Schneider

Laurent showed a better way

The problem with echo is that it is run only once. That means, if you
are on usellx42 and do ssh usellx41, the header will change to
usellx41. But when you log off, the title will not be reset and will be
misleading (usellx41).


My approach is to set in in PS1, so that it will always be correct.


Ex in .kshrc
PS1=$(echo -e "\033]0;${USER}@${HOSTNAME} \007  ${USER}@${HOSTNAME}$ ")



Cheers,
Laurent


TrackBack

TrackBack URL for this entry:
http://blogs.oracle.com/mte1521/mt-tb.cgi/2126

Comments (3)

The problem with echo is that it is run only once. That means, if you are on usellx42 and do ssh usellx41, the header will change to usellx41. But when you log off, the title will not be reset and will be misleading (41).
My approach is to set in in PS1, so that it will always be correct.
Ex in .kshrc
PS1=$(echo -e '\033]0;$USER@$HOST\007$USER@$HOST $ ')

Cheers,
Laurent

Gaurav Verma:

Thanks a lot for your comment, Laurent.

I appreciate you going through the posting and suggesting an improvement. I have taken the liberty of posting it along with crediting it to you.

If you would like to author some articles of general interest, Please feel free to let me know and you are author them on the blog.

Thanks
Gaurav

unfortunately, the backslashes before 033 and 007 disappear in my example

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on September 5, 2007 9:59 PM.

The previous post in this blog was When adcustomizer.sh may not work...

The next post in this blog is Do I need permission to make ssh keys work?.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type and Oracle