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


Comments:

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

Posted by Laurent Schneider on September 05, 2007 at 08:03 PM EDT #

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

Posted by Gaurav Verma on September 06, 2007 at 03:24 AM EDT #

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

Posted by Laurent Schneider on September 06, 2007 at 05:51 PM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

bocadmin_ww

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today