[NTLUG:Discuss] Bash can put the current command into your xterm title

Lance Simmons lance at lsimmons.net
Tue Aug 20 19:54:42 CDT 2002


The xterm title mini-howto at tldp.org doesn't yet contain information
on using bash to dynamically insert the name of the current command into
the xterm title.  (It says that only zsh and tcsh can do it.)  Paul Jarc
in an email explained to me how to do it.  It's pretty cool.  You need
bash 2.05b, and should make sure that neither PS1 nor PROMPT_COMMAND has
xterm-related escape characters in it.  Maybe it's best just to comment
out PS1 and PROMPT_COMMAND until you get a feel for how this works.

Then add these lines to your .bashrc:

 xtitle() { echo -ne "\\E]2\;$1 $USER@$HOSTNAME\\a"; }
 trap 'xtitle "[$(history 1 | cut -b 8-30)]"' DEBUG

The result is an xterm title that looks like this:

 "[first 30 character of current command] $USER@$HOSTNAME"

You can play around with this and produce lots of other effects.  I've
wanted to be able to do this for a long time, and now I finally can! No
more xterminals named "Terminal"!

-- 
 .~.
 /V\   Lance Simmons
/( )\  lance at lsimmons.net
^^-^^




More information about the Discuss mailing list