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

Lance Simmons lance at lsimmons.net
Tue Aug 20 21:13:36 CDT 2002


On Tue, Aug 20, 2002 at 07:54:42PM -0500, Lance Simmons wrote:
> 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

That works for gnome-terminal, but doesn't seem to work for xterm and
rxvt. Instead, try:

 xtitle() { echo -ne "\033]0;$1 $USER@$HOSTNAME:$PWD\007"; }
 trap 'xtitle "[$(history 1 | cut -b 8-30)]"' DEBUG

The basic idea is simple: you just have to get the escape characters
right.

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




More information about the Discuss mailing list