cancel
Showing results for 
Search instead for 
Did you mean: 

xterm window title

SOLVED
Go to solution
Andy Kosela
Frequent Advisor

xterm window title

How to dynamically change xterm window title using POSIX sh? What is the correct escape sequence?
7 REPLIES
OldSchool
Honored Contributor
Solution

Re: xterm window title

take a look at this page:

http://www.shelldorado.com/shelltips/beginner.html

several references to that topic there, including the following:

The title of a XTERM window can be set using the following
escape sequence:

ESC ] 0 ; title ^G

Example:

echo "^[]0;This is a title^G"

Enter the escape character (the first character of the
string) as CTRL-V ESC. On the screen you will see "^[". The
last character is entered as CTRL-V CTRL-G.
Steven Schweda
Honored Contributor

Re: xterm window title

No bets, but I have a DCL procedure which
does these:

esc+ "]2;"+ "Window Title Text"+ bel

esc+ "]1;"+ "Icon Title Text"+ bel

where esc = 27, and bel = 7.

You'll need to reform the expressions for use
in a UNIX shell.
Andy Kosela
Frequent Advisor

Re: xterm window title

OK, this is PS1:

export PS1="^[]0;`hostname | cut -d. -f1`:^G^M`tput bold``hostname | cut -d. \
-f1``tput rmso`":'$PWD# '

The problem is that when I move cursor to the far right corner of the screen it tries to fold line too early (it seems by the hostname string characters). What is the best way to overcome this and have cursor reach the screen till the end?

Dennis Handly
Acclaimed Contributor

Re: xterm window title

The way I handle it is that I only change the title when I do cd, pushd or popd. And my PS1 is always "$ ". I have a bunch of real shell functions that handle this.
Andy Kosela
Frequent Advisor

Re: xterm window title

Dennis,

Ok but that doesn't solve the issue. With the title line you can just put ^M, but with the hostname in prompt there is still a problem.
Dennis Handly
Acclaimed Contributor

Re: xterm window title

>with the hostname in prompt there is still a problem.

As I said, there is no reason to waste screen real estate with long prompts. I put the hostname in the title and the icon title.
Andy Kosela
Frequent Advisor

Re: xterm window title

Call me old school, but I prefer full screen putty sessions and the most important information I need is hostname and pwd. I had a similar problem in tcsh, but I managed to get rid of that by correctly formatting prompt variable. Now if only I were able to do the same in POSIX sh.... Anyone?