86 lines
3.2 KiB
HTML
86 lines
3.2 KiB
HTML
<!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: Dynamic titles</TITLE>
|
|
<LINK HREF="Xterm-Title-4.html" REL=next>
|
|
<LINK HREF="Xterm-Title-2.html" REL=previous>
|
|
<LINK HREF="Xterm-Title.html#toc3" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="Xterm-Title-4.html">Next</A>
|
|
<A HREF="Xterm-Title-2.html">Previous</A>
|
|
<A HREF="Xterm-Title.html#toc3">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="s3">3. Dynamic titles</A></H2>
|
|
|
|
<P>Many people find it useful to set the title of a terminal to reflect
|
|
dynamic information, such as the name of the host the user is logged
|
|
into, the current working directory, etc.
|
|
<P>
|
|
<P>
|
|
<H2><A NAME="ss3.1">3.1 xterm escape sequences</A>
|
|
</H2>
|
|
|
|
<P>Window and icon titles may be changed in a running xterm
|
|
by using XTerm escape sequences. The following sequences
|
|
are useful in this respect:
|
|
<UL>
|
|
<LI><CODE>ESC]0;<B>string</B>BEL</CODE> -- Set icon name and window title
|
|
to <B>string</B></LI>
|
|
<LI><CODE>ESC]1;<B>string</B>BEL</CODE> -- Set icon name to <B>string</B></LI>
|
|
<LI><CODE>ESC]2;<B>string</B>BEL</CODE> -- Set window title to
|
|
<B>string</B></LI>
|
|
</UL>
|
|
|
|
where <CODE>ESC</CODE> is the <B>escape</B> character (\033), and <CODE>BEL</CODE> is
|
|
the <B>bell</B> character (\007).
|
|
<P>
|
|
<P>Printing one of these sequences within the xterm will cause the
|
|
window or icon title to be changed.
|
|
<P>
|
|
<P><B>Note</B>: these sequences apply to most xterm derivatives,
|
|
such as <CODE>nxterm</CODE>, <CODE>color-xterm</CODE> and <CODE>rxvt</CODE>. Other
|
|
terminal types often use different escapes; see the
|
|
appendix for examples. For the full list of
|
|
xterm escape sequences see the file
|
|
<A HREF="http://www.giccs.georgetown.edu/~ric/howto/Xterm-Title/ctlseq2.txt">ctlseq2.txt</A>,
|
|
which comes with the xterm distribution, or
|
|
<A HREF="http://www.giccs.georgetown.edu/~ric/howto/Xterm-Title/xterm.seq">xterm.seq</A>, which comes with the
|
|
<A HREF="http://www.rxvt.org/">rxvt</A> distribution.
|
|
<P>
|
|
<P>
|
|
<H2><A NAME="ss3.2">3.2 Printing the escape sequences</A>
|
|
</H2>
|
|
|
|
<P>For information that is constant throughout the lifetime of
|
|
this shell, such as host and username, it will suffice to
|
|
simply echo the escape string in the shell rc file:
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
echo -n "\033]0;${USER}@${HOST}\007"
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
|
|
should produce a title like <CODE>username@hostname</CODE>, assuming
|
|
the shell variables <CODE>$USER</CODE> and <CODE>$HOST</CODE> are set correctly.
|
|
The required options for <CODE>echo</CODE> may vary by shell (see examples
|
|
below).
|
|
<P>
|
|
<P>For information that may change during the shell's lifetime, such
|
|
as current working directory, these escapes really need to be
|
|
applied every time the prompt changes.
|
|
This way the string is updated with every command you issue and can keep
|
|
track of information such as current working directory, username, hostname,
|
|
etc. Some shells provide special functions for this purpose, some don't
|
|
and we have to insert the title sequences directly into the prompt
|
|
string. This is illustrated in the next section.
|
|
<P>
|
|
<P>
|
|
<HR>
|
|
<A HREF="Xterm-Title-4.html">Next</A>
|
|
<A HREF="Xterm-Title-2.html">Previous</A>
|
|
<A HREF="Xterm-Title.html#toc3">Contents</A>
|
|
</BODY>
|
|
</HTML>
|