note to self....

http://blogs.earthside.org/note_to_self/

Saturday, May 21, 2005

FAQ: XTerm Titles, Bash Prompts, Cygwin, and Linux

There is a Linux mini-HowTo entitled How to change the title of an xterm. This how to covers several shells and has a lot of good information about the various escape sequences of various shells and how to use them.

The section 4.3 Bash has example code for setting the XTerm title from within Bash.

The Bash shell uses the value of the environment variable PS1 as the prompt. The default Bash prompt set during the installation of the Cygwin environment uses the escape sequences described in the How-To to set the title of an XTerm.

This is fine, unless you want to use the same prompt value in the .bashrc file on a Linux box. The technique does work, but cases some annoying behaviour at the console when you log in to the Linux box without the benefit of the X environment.

Also, the dynamic setting of the XTerm title can interfere with static title settings you may try to use.

Now that we know the escape sequences that are used to set the XTerm title, we can examine the default Cygwin prompt and re-write it to leave the XTerm title alone, while still giving us the two-line prompt that can be useful for readability.

The default value is something like:
export PS1='\[\033]0;\w\007\033[32m\]\u@\h: \[\033[33m\w\033[0m\]
\$'
We can re-write this as
export PS1='\033[32m\]\u@\h: \[\033[33m\w\033[0m\]
\$'
This keeps the Bash prompt, but doesn't try to set the XTerm title.

Note that the bashrc file can contain code that checks the value of $TERM before setting the prompt. That would eliminate the problem that occurs for console logins, but still won't help us when we're setting the XTerm title ourselves e.g. using -n and -T. We prefer to simply remove the dynamic setting of the XTerm title as a default.

references

The document How to change the title of an xterm is Linux HOWTO Index and can be found at http://sunsite.unc.edu/LDP/HOWTO/mini/Xterm-Title.html.

The latest version can always be found in several formats at http://www.giccs.georgetown.edu/~ric/howto/Xterm-Title/.

The Bash shell homepage: http://www.gnu.org/software/bash/bash.html

Labels: , , , , , , , , ,






<< Home

Archives

2004/09   2005/03   2005/04   2005/05   2005/06   2005/07   2005/08   2005/09   2005/10   2005/11   2006/01   2006/02   2006/04   2006/05   2006/06   2008/01  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]