Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > by-pkgid > 965e33040dd61030a94f0eb89877aee8 > files > 7246

howto-html-en-20080722-2mdv2010.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE>How to change the title of an xterm: Printing the current job name</TITLE>
 <LINK HREF="Xterm-Title-6.html" REL=next>
 <LINK HREF="Xterm-Title-4.html" REL=previous>
 <LINK HREF="Xterm-Title.html#toc5" REL=contents>
</HEAD>
<BODY>
<A HREF="Xterm-Title-6.html">Next</A>
<A HREF="Xterm-Title-4.html">Previous</A>
<A HREF="Xterm-Title.html#toc5">Contents</A>
<HR>
<H2><A NAME="s5">5. Printing the current job name</A></H2>

<P>Often a user will start a long-lived foreground job such as <CODE>top</CODE>,
an editor, an email client, etc, and wishes the name of the job
to be shown in the title. This is a more thorny problem and is
only achieved easily in <CODE>zsh</CODE>.
<P>
<H2><A NAME="ss5.1">5.1 zsh</A>
</H2>

<P><CODE>zsh</CODE> provides an ideal builtin function for this purpose:
<BLOCKQUOTE><CODE>
<PRE>
preexec()   a function which is just before a command is executed
$*,$1,...   arguments passed to preexec()
</PRE>
</CODE></BLOCKQUOTE>

Thus, we can insert the job name in the title as follows:
<BLOCKQUOTE><CODE>
<PRE>
case $TERM in
    xterm*)
      preexec () {
        print -Pn "\e]0;$*\a"
      }
    ;;
esac
</PRE>
</CODE></BLOCKQUOTE>

Note: the <CODE>preexec()</CODE> function appeared around version 3.1.2
of <CODE>zsh</CODE>, so you may have to upgrade from an earlier version.
<P>
<P>
<H2><A NAME="ss5.2">5.2 Other shells</A>
</H2>

<P>This is not easy in other shells which lack an equivalent of the
<CODE>preexec()</CODE> function. If anyone has examples please email
them to the author.
<P>
<P>
<HR>
<A HREF="Xterm-Title-6.html">Next</A>
<A HREF="Xterm-Title-4.html">Previous</A>
<A HREF="Xterm-Title.html#toc5">Contents</A>
</BODY>
</HTML>