IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

HOWTOs

Search Howtos :Match :

6.3. Xterm Title Bar Manipulations

I'm not sure that these escape sequences strictly qualify as "ANSI Escape Sequences," but in practice their use is almost identical so I've included them in this chapter.

Non-printing escape sequences can be used to produce interesting effects in prompts. To use these escape sequences, you need to enclose them in \[ and \] (as discussed in Section 3.4, telling Bash to ignore this material while calculating the size of the prompt. Failing to include these delimiters results in line editing code placing the cursor incorrectly because it doesn't know the actual size of the prompt. Escape sequences must also be preceded by \033[ in Bash prior to version 2, or by either \033[ or \e[ in later versions.

If you try to change the title bar of your Xterm with your prompt when you're at the console, you'll produce garbage in your prompt. To avoid this, test the TERM environment variable to tell if your prompt is going to be in an Xterm.

function proml
{
case $TERM in
    xterm*)
        local TITLEBAR='\[\033]0;\u at \h:\w\007\]'
        ;;
    *)
        local TITLEBAR=''
        ;;
esac

PS1="${TITLEBAR}\
[\$(date +%H%M)]\
[\u at \h:\w]\
\$ "
PS2='> '
PS4='+ '
}

This is a function that can be incorporated into ~/.bashrc. The function name could then be called to execute the function. The function, like the PS1 string, is stored in the environment. Once the PS1 string is set by the function, you can remove the function from the environment with unset proml. Since the prompt can't change from being in an Xterm to being at the console, the TERM variable isn't tested every time the prompt is generated. I used continuation markers (backslashes) in the definition of the prompt, to allow it to be continued on multiple lines. This improves readability, making it easier to modify and debug.

The first step in creating this prompt is to test if the shell we're starting is an xterm or not: if it is, the shell variable (${TITLEBAR}) is defined. It consists of the appropriate escape sequences, and \u at \h:\w, which puts <user> at <machine>:<working directory> in the Xterm title bar. This is particularly useful with minimized Xterms, making them more rapidly identifiable. The other material in this prompt should be familiar from previous prompts we've created.

The only drawback to manipulating the Xterm title bar like this occurs when you log into a system on which you haven't set up the title bar hack: the Xterm will continue to show the information from the previous system that had the title bar hack in place.

A suggestion from Charles Lepple () on setting the window title of the Xterm and the title of the corresponding icon separately. He uses this under WindowMaker because the title that's appropriate for an Xterm is usually too long for a 64x64 icon. "\[\e]1;icon-title\007\e]2;main-title\007\]". He says to set this in the prompt command because "I tried putting the string in PS1, but it causes flickering under some window managers because it results in setting the prompt multiple times when you are editing a multi-line command (at least under bash 1.4.x -- and I was too lazy to fully explore the reasons behind it)." I had no trouble with it in the PS1 string, but didn't use any multi-line commands. He also points out that it works under xterm, xwsh, and dtterm, but not gnome-terminal (which uses only the main title). I also found it to work with rxvt, but not kterm.

Search Howtos :Match :
PhpMyAdmin 3.2.4 rc1
Php front-end to MySQL administration
Exim 4.71
Message transfer agent
Opera 10.10
Opera for Linux
ImageMagick 6.5.7.10
ImageMagick image processing studio
DeleGate 9.9.6-pre6
Proxy server which runs on multiple platforms
Inkscape 0.47
Vector graphic editor for SVG
Nano 2.1.99pre2
Emulate Pico while also offering a few enhancements.
Google Chrome Browser 4.0.249.11
Google’s open source browser project
Rhythmbox 0.12.6
Integrated music management application
Tellico 2.1.1
Collection manager for books, music, videos, and bibliographies
Free IT Magazines, White Papers, eBooks, and more !
Oracle Magazine

Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.

Vulnerability Management for Dummies

Get all the Facts and See How to Implement a Successful Vulnerability Management Program.

Website Magazine

Has tapped premier talent in the Internet industry for our content and each and every issue will contain practical advice and insights for website owners.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info