\documentclass[letterpaper]{article}
\nonstopmode
\akai
\usepackage{linuxdoc-sgml}
\usepackage{qwertz}
\usepackage{url}
\usepackage[latin1]{inputenc}
\usepackage{t1enc}
\usepackage[english]{babel}
\usepackage{epsfig}
\usepackage{null}
\def\addbibtoc{
\addcontentsline{toc}{section}{\numberline{\mbox{}}\relax\bibname}
}%end-preamble
\setcounter{page}{1}
\title{ÈçºÎ±ä¸ü xterm µÄÖ÷Ìâ}
\author{Ric Lister, {\ttfamily ric@giccs.georgetown.edu}\\ 
ÒëÕß: ÔøÔªÓÓ {\ttfamily \onlynameurl{yytseng@ms16.hinet.net}}}
\date{v2.0, 1999 ÄêÊ®ÔÂ 27 ÈÕ}
\abstract{±¾ÎÄ½âÊÍÈçºÎÊ¹ÓÃÒçÎ»ÐòÁÐÒÔ¶¯Ì¬±ä¸ü xterm µÄÊÓ´°¼°Í¼Ê¾.
¡õÀýÖÐ, °üº¬ÊýÖÖÃüÁî½âÒëÆ÷Óï·¨. ¶ø¸½Â¼ÒàÁÐ³ö¸øÆäËûÀàÐÍÖÕ¶Ë»úÊ¹ÓÃµÄÒçÎ»ÐòÁÐ.}


\begin{document}
\maketitle
\tableofcontents

\section{¿ÉÒÔÔÚÄÄÕÒµ½Õâ·ÝÎÄ¼þ}

Õâ·ÝÎÄ¼þÏÖÒÑÊÇ 
\nameurl{http://sunsite.unc.edu/LDP/HOWTO/}{Linux HOWTO Index}
µÄÒ»²¿·Ý, Òà¿ÉÒÔÔÚÕâÕÒµ½ 
\nameurl{http://sunsite.unc.edu/LDP/HOWTO/mini/Xterm-Title.html}{}.



×îÐÂ°æ±¾µÄ¸÷ÖÖÎÄ¼þ¸ñÊ½¶¼¿ÉÒÔÔÚÕâÕÒµ½ 
\nameurl{http://www.giccs.georgetown.edu/~ric/howto/Xterm-Title/}{}.



±¾ÎÄÈ¡´úÁËÔ­±¾ÓÉ Winfried Tr\"umper ËùÐ´µÄ howto.






\section{¾²Ì¬Ö÷Ìâ}

ÈÎÒ»ÖÖÖÕ¶Ë»ú {\ttfamily xterm},
{\ttfamily color-xterm} »ò {\ttfamily rxvt} ¶¼¿ÉÒÔ½åÓÉ {\ttfamily -T} ¼° {\ttfamily -n}
µÄ²ÎÊýÉè¶¨À´Éè¶¨¾²Ì¬Ö÷Ìâ:
\begin{tscreen}
xterm -T "My XTerm's Title" -n "My XTerm's Icon Title"
\end{tscreen}







\section{¶¯Ì¬Ö÷Ìâ}

Ðí¶àÈË·¢ÏÖÕâÔÚÏÔÊ¾Ò»Ð©¶¯Ì¬×ÊÑ¶Ê±Ïàµ±ÓÐÓÃ, ±ÈÈç Ê¹ÓÃÕßËùµÇÈëµÄÖ÷»úÃû³Æ,
ÏÖÐÐµÄ¹¤×÷Ä¿Â¼, µÈµÈ.






\subsection{xterm ÒçÎ»ÐòÁÐ}

Ò»¸öÒÑÔÚÖ´ÐÐµÄ xterm µÄÊÓ´°¼°Í¼Ê¾µÄÖ÷Ìâ¶¼¿ÉÒÔÍ¸¹ýÒçÎ»ÐòÁÐÀ´±ä¸ü.
ÏÂÁÐÁÐ³ö¸úÕâ¸öÉè¶¨ÓÐ¹ØµÄÐòÁÐ:
\begin{itemize}
\item {\ttfamily ESC]0;{\bfseries string}BEL} -- Éè¶¨Í¼Ê¾¼°ÊÓ´°µÄÖ÷ÌâÎª
{\bfseries string}
\item {\ttfamily ESC]1;{\bfseries string}BEL} -- Éè¶¨Í¼Ê¾ÃûÎª {\bfseries string}
\item {\ttfamily ESC]2;{\bfseries string}BEL} -- Éè¶¨ÊÓ´°Ö÷ÌâÎª
{\bfseries string}
\end{itemize}

ÔÚÕâÀï {\ttfamily ESC} ÊÇÖ¸ {\bfseries escape} ×ÖÔª ($\backslash$033), ¶ø{\ttfamily BEL} ÊÇÖ¸
{\bfseries bell} ×ÖÔª ($\backslash$007).



ÔÚ xterm ÀïÍ·¾Í¿ÉÒÔÊ¹µÃÊÓ´°¼°Í¼Ê¾µÄÖ÷Ìâ±ä¸ü.



{\bfseries ×¢Òâ}: ÕâÐ©ÐòÁÐ¿ÉÒÔÓ¦ÓÃµ½´ó²¿·Ý xterm ÑÜÉúµÄ³ÌÊ½,
±ÈÈç {\ttfamily nxterm}, {\ttfamily color-xterm} ¼° {\ttfamily rxvt}. ÆäËûµÄ
ÖÕ¶Ë»úÀàÐÍ´ó¶¼Ê¹ÓÃ²»Ò»ÑùµÄÐòÁÐ; ²Î¿¼¸½Â¼ËùÁÐ¾ÙµÄ¡õÀý.
ÈçÒª²Î¿¼ xterm ËùÓÐµÄÒçÎ»ÐòÁÐ²Î¿¼Õâ¸öµµ°¸
\nameurl{http://www.giccs.georgetown.edu/~ric/howto/Xterm-Title/ctlseq2.txt}{ctlseq2.txt},
Õâ»áËæÖø xterm µÄÌ×¼þ·¢ÐÐ, »ò
\nameurl{http://www.giccs.georgetown.edu/~ric/howto/Xterm-Title/xterm.seq}{xterm.seq}, ËæÖø
\nameurl{http://www.rxvt.org/}{rxvt} Ì×¼þ·¢ÐÐ.






\subsection{Ó¡³öÕâÐ©ÐòÁÐ}

ÓÐÐ©×ÊÑ¶ÔÚÃüÁî½âÒëÆ÷µÄÉúÃüÖÜÆÚÖÐÊÇ×ÔÊ¼ÖÁÖÕ¶¼²»±äµÄ,
±ÈÈç Ö÷»úÃû³Æ ¼° Ê¹ÓÃÕßÃû³Æ, ÄÇ÷áÔÚÃüÁî½âÒëÆ÷µÄ³õÊ¼Æô¶¯µµ
(rc file) ÓÃ echo Ö¸ÁîÓ¡³öÕâÐ©×Ö´®¾Í¹»ÁË:
\begin{tscreen}
\begin{verbatim}
echo -n "\033]0;${USER}@${HOST}\007"
\end{verbatim}
\end{tscreen}

Ó¦¸Ã»á²úÉúÏñ {\ttfamily username@hostname} ÕâÑùµÄÖ÷Ìâ,
¼ÙÉèÃüÁî½âÒëÆ÷µÄ±äÊý {\ttfamily \$USER} ¼° {\ttfamily \$HOST} ¶¼ÒÑÉè¶¨ÕýÈ·µÄ»°.
{\ttfamily echo} ËùÐèµÄÑ¡ÏîÒÀÃüÁî½âÒëÆ÷Ê¹ÓÃµÄÀàÐÍ¶øÓÐËù²»Í¬ (²Î¿¼ÏÂÃæµÄËµÃ÷).



ÓÐÐ©×ÊÑ¶ÔÚÃüÁî½âÒëÆ÷µÄÉúÃüÖÜÆÚÖÐÊÇÒ»Ö±ÔÚ±äµÄ,
±ÈÈç ÏÖÐÐ¹¤×÷Ä¿Â¼, ÕâÐ©ÒçÎ»×ÊÑ¶¾Í±ØÐëÔÚÃ¿´ÎÌáÊ¾×ÖÔª±ä»¯Ê±ËæÖø¸Ä±ä. 
ÕâÏÂ×Ó×Ö´®¾Í»áÔÚÃ¿´ÎÄãÊäÈëÃüÁîÊ±¸üÐÂ,
¶øÇÒÄã»¹¿ÉÒÔ×·×Ù±£Áô ÏÖÐÐÄ¿Â¼, Ê¹ÓÃÕßÃû, Ö÷»úÃû, µÈ×ÊÑ¶.
²¿·ÝÃüÁî½âÒëÆ÷Ìá¹©ÕâÀàÓÃÍ¾µÄÌØÊâ¹¦ÄÜ,
ÓÐÐ©ÔòÃ»ÓÐ. ¶øÎÒÃÇ¾Í±ØÐëÖ±½Ó²åÈëÖ÷ÌâÒçÎ»×ÊÑ¶µ½ÌâÊ¾×Ö´®ÖÐ.
Õâ»áÔÚÏÂÒ»½ÚÖÐËµÃ÷






\section{¸÷ÖÖÃüÁî½âÒëÆ÷µÄ¡õÀý}

ÒÔÏÂÎÒÃÇÌá¹¦Ò»Ð©¡õÀý¸ø³£¼ûµÄÃüÁî½âÒëÆ÷Ê¹ÓÃ.
ÎÒÃÇÏÈ´Ó {\ttfamily zsh} ¿ªÊ¼,
Ëû¿ÉÒÔÌá¹©Ðí¶àÁéÇÉµÄ»úÖÆÊ¹µÃÎÒÃÇºÜÈÝÒ×µØÍê³ÉÎÒÃÇËùÒªµÄ¹¤×÷.
È»ááÎÒÃÇÔÙ½øÕ¹µ½ÄÑ¶È½Ï¸ßµÄ¡õÀý.



ÔÚËùÓÐµÄ¡õÀýÖÐÎÒÃÇ¶¼²âÊÔÁË {\ttfamily \$TERM} »·¾³±äÊý.
ÒÔÈ·¶¨ÎÒÃÇÖ»Ðè°ÑÕâ¸öÒçÎ»×ÊÑ¶ËÍµ½ xterm. ÎÒÃÇ¶Ô
{\ttfamily \$TERM=xterm*} ×ö²âÊÔ; ÍòÓÃ×ÖÔªÊÇÒòÎªÐ©ÐíµÄ²îÒìÐÔ
(±ÈÈç rxvt) »áÉè¶¨ {\ttfamily \$TERM=xterm-color}.



ÎÒÃÇÒª¶Ô C ÃüÁî½âÒëÆ÷ (C Shell) ×åÏµ×÷ÌØ±ðµÄ×¢½â, ±ÈÈç
{\ttfamily tcsh} ¼° {\ttfamily csh}.
ÔÚ C ÃüÁî½âÒëÆ÷, Ê¹ÓÃµ½Î´¶¨ÒåµÄ±äÊý¾ÍËãÊÇÖÂÃüÐÔµÄ´íÎó.
Òò´Ë, ÔÚ²âÊÔ±äÊý {\ttfamily \$TERM} Ö®Ç°,
ÏÈÈ·¶¨ÆäÊÇ·ñ´æÔÚ·ñÔò»áÊ¹ÔÚ·Ç½»Ì¸Ä£Ê½ÏÂ¹¤×÷µÄÃüÁî½âÒëÆ÷Í£°Ú.
Òª´ïµ½Õâ¸öÄ¿µÄÄã±ØÐë°Ñ²¿·Ý¶«Î÷ÓÃÏÂÃæÕâÖÖÑùÊ½°üÆðÀ´:
\begin{tscreen}
\begin{verbatim}
  if ($?TERM) then
      ...
  endif
\end{verbatim}
\end{tscreen}

(ÎÒÃÇÊÇ²»Ö÷ÕÅÓÃ C ÃüÁî½âÒëÆ÷ µÄÀíÓÉÖ®Ò». ²Î¿¼
{\itshape \nameurl{http://language.perl.com/versus/csh.whynot}{Csh Programming Considered Harmful}\/} ÓÐºÜ¶àÓÐÓÃµÄÌÖÂÛÎÄÕÂ).



ÒÔÏÂµÄ¡õÀý¿ÉÒÔ±»ÓÃÀ´²åÈëµ½ºÏÊÊµÄÃüÁî½âÒëÆ÷µÄ³õÊ¼Æô¶¯µµ;
¼´ ÄÇ¸öÔÚ½»Ì¸Ê½ÃüÁî½âÒëÆ÷Æô¶¯Ê±»áÈ¥¶ÁµÄÄÇ¸öµµ.
ÔÚ´ó²¿·ÝµÄÇé¿öËü±»³ÆÎª
{\ttfamily .{\itshape ÃüÁî½âÒëÆ÷Ãû\/}rc} (Èç {\ttfamily .zshrc}, {\ttfamily .tcshrc}, µÈ).








\subsection{zsh}

{\ttfamily zsh} Ìá¹©²¿·Ý¹¦ÄÜÓëÑÓÉì¹¦ÄÜ, ¶øÎÒÃÇ½«ÓÃµ½:
\begin{tscreen}
\begin{verbatim}
precmd ()   Ò»¸öÔÚÌáÊ¾ÃüÁîÇ°±ØÖ´ÐÐµÄ¹¦ÄÜº¬Ê½
chpwd ()    Ò»¸öÔÚÄ¿Â¼ÓÐËù±ä»¯Ê±»áÖ´ÐÐµÄ¹¦ÄÜº¬Ê½
\e          ÒçÎ»×ÖÔª (ESC)
\a          bell µÄÒçÎ»×ÖÔª (BEL)
%n          ±»½âÊÍÎª $USERNAME
%m          ±»½âÊÍÎªÖ÷»úÃû³ÆÔÚµÚÒ»¸ö '.' Ö®Ç°µÄ²¿·Ý
%~          ±»½âÊÍÎªÄ¿Â¼, ÒÔ '~' È¡´ú $HOME
\end{verbatim}
\end{tscreen}

¸ü¶àµÄÑÓÉì¹¦ÄÜ: ²Î¿¼ {\ttfamily zshmisc} Ê¹ÓÃÊÖ²á.



Òò´Ë, ÒÔÏÂ½«Éè¶¨ xterm µÄÖ÷ÌâÎª
"{\ttfamily {\itshape username\/}@{\itshape hostname\/}: {\itshape directory\/}}":
\begin{tscreen}
\begin{verbatim}
case $TERM in
    xterm*)
        precmd () {print -Pn "\e]0;%n@%m: %~\a"}
        ;;
esac
\end{verbatim}
\end{tscreen}

ÕâÒ²¿ÉÒÔÓÃ {\ttfamily chpwd()} È¡´ú
{\ttfamily precmd()} À´´ï³É. {\ttfamily print} ÄÚ½¨µÄ¹¤×÷ÊÇ¸ú
{\ttfamily echo} Ò»Ñù, µ«¿ÉÒÔÈÃÎÒÃÇÈ¥´æÈ¡ {\ttfamily \%} ÃüÁîÌáÊ¾ÒçÎ»×ÊÑ¶.






\subsection{tcsh}

{\ttfamily tcsh} µÄ²¿·Ý¹¦ÄÜº¬Ê½ÓëÑÓÉì¹¦ÄÜÓë {\ttfamily zsh} ÏàÍ¬:
\begin{tscreen}
\begin{verbatim}
precmd ()   Ò»¸öÔÚÌáÊ¾ÃüÁîÇ°±ØÖ´ÐÐµÄ¹¦ÄÜº¬Ê½
cwdcmd ()   Ò»¸öÔÚÄ¿Â¼ÓÐËù±ä»¯Ê±»áÖ´ÐÐµÄ¹¦ÄÜº¬Ê½
%n          ±»½âÊÍÎª $USERNAME
%m          ±»½âÊÍÎªÖ÷»úÃû³Æ
%~          ±»½âÊÍÎªÄ¿Â¼, ÒÔ '~' È¡´ú $HOME
%#          ¶ÔÕý³£µÄÊ¹ÓÃÕß½âÊÍÎª '>', ¶ø³¬¼¶Ê¹ÓÃÕßÔòÎª '#'
%{...%}     ÒýÈëÒ»¸ö×Ö´®ÎªÁ¬ÐøµÄÒçÎ»ÐòÁÐ
\end{verbatim}
\end{tscreen}




²»ÐÒµÄ, ²¢Ã»ÓÐÓë {\ttfamily zsh} µÄ {\ttfamily print} ÏàÍ¬¹¦ÄÜµÄÖ¸Áî,
ÄÜÈÃÎÒÃÇÔÚÖ÷Ìâ×Ö´®ÖÐÊ¹ÓÃÌáÊ¾ÒçÎ»×ÊÑ¶,
Òò´ËÎÒÃÇÎ¨Ò»ÄÜÊ¹ÓÃµÄÃüÁî½âÒëÆ÷±äÊý (ÔÚ {\ttfamily \~{}/.tcshrc}):
\begin{tscreen}
\begin{verbatim}
switch ($TERM)
    case "xterm*":
        alias precmd 'echo -n "\033]0;${HOST}:$cwd\007"'
        breaksw
endsw
\end{verbatim}
\end{tscreen}

È»¶ø, Õâ»áÓÃÄ¿Â¼ÍêÕûµÄÂ·¾¶È¡´úÊ¹ÓÃ {\ttfamily \~{}}.
¸Ä°ÑÕâÐ©×Ö´®²åÈëÌâÊ¾×ÖÔª:
\begin{tscreen}
\begin{verbatim}
switch ($TERM)
    case "xterm*":
        set prompt="%{\033]0;%n@%m:%~\007%}tcsh%# "
        breaksw
    default:
        set prompt="tcsh%# "
        breaksw
endsw
\end{verbatim}
\end{tscreen}

Õâ»áÉè¶¨ "{\ttfamily tcsh\% }" µÄÌáÊ¾×ÖÔª, ¶ø xterm µÄÖ÷Ìâ¼°Í¼Ê¾Îª
"{\ttfamily {\itshape username\/}@{\itshape hostname\/}: {\itshape directory\/}}". Òª×¢Òâ
"{\ttfamily \%$\{$...\%$\}$}" ±ØÐë»·ÈÆÔÚÒçÎ»ÐòÁÐÍâ
(ÇÒ²»ÄÜ±»·ÅÔÚ ÌáÊ¾µÄ×îááÒ»Ïî: ²Î¿¼ {\ttfamily tcsh} Ê¹ÓÃÊÖ²áËµÃ÷»á¸üÏêÏ¸).






\subsection{bash}

{\ttfamily bash} Ö§Ô®±äÊý {\ttfamily \$PROMPT\_COMMAND}
ÄÚº¬Ò»¸öÖ¸ÁîÔÚÌáÊ¾×ÖÔªÖ®Ç°Ö´ÐÐ. Õâ¸ö¡õÀý½«Éè¶¨Ö÷ÌâÎª
{\ttfamily username@hostname: directory}:
\begin{tscreen}
\begin{verbatim}
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
\end{verbatim}
\end{tscreen}

ÔÚÕâµÄ {\ttfamily $\backslash$033} ÊÇ´ú±í×ÖÔª {\ttfamily ESC},
¶ø {\ttfamily $\backslash$007} ÔòÊÇ {\ttfamily BEL}.



¼Ç×¡ÒýºÅÔÚÕâÏàµ±ÖØÒª: »á±»½âÊÍµÄ±äÊýÊÇ·ÅÔÚ
{\ttfamily "..."}, ¶ø²»ÊÇ {\ttfamily '...'}. Òò´Ë
{\ttfamily \$PROMPT\_COMMAND} ÊÇ±»Éè¶¨ÎªÒ»¸ö²»±»½âÊÍµÄÖµ,
µ«±äÊýÔÚ {\ttfamily "..."} ¡õÈç¹ûÓÐÓÃµ½ {\ttfamily \$PROMPT\_COMMAND} Ôò»á±»½âÊÍ.



È»¶ø, {\ttfamily \$PWD} ²úÉúÍêÕûµÄÂ·¾¶.
Èç¹ûÎÒÃÇÒªÊ¹ÓÃ {\ttfamily \~{}} ÕâÖÖËÙ¼Ç, ÔòÎÒÃÇÒª°ÑÒçÎ»×Ö´®Ç¶Èëµ½ÌáÊ¾×ÖÔª,
Õâ»áÈÃÎÒÃÇ¿ÉÒÔÀûÓÃÃüÁî½âÒëÆ÷ËùÌá¹©µÄÃüÁîÁÐÑÓÉì¹¦ÄÜ:
\begin{tscreen}
\begin{verbatim}
\u          ±»½âÊÍÎª $USERNAME
\h          ±»½âÊÍÎªÖ÷»úÃû³ÆÔÚµÚÒ»¸ö '.' Ö®Ç°µÄ²¿·Ý
\w          ±»½âÊÍÎªÄ¿Â¼, ÒÔ '~' È¡´ú $HOME
\$          ¶ÔÕý³£µÄÊ¹ÓÃÕß½âÊÍÎª '>', ¶ø³¬¼¶Ê¹ÓÃÕßÔòÎª '#'
\[...\]     Ç¶Èë·ÇÁÐÓ¡×ÖÔªÒçÎ»ÐòÁÐ
\end{verbatim}
\end{tscreen}




Òò´Ë, ÒÔÏÂ½«²úÉú {\ttfamily bash\$} µÄÌáÊ¾×ÖÔª,
²¢Éè¶¨ xterm µÄÖ÷ÌâÎª {\ttfamily username@hostname: directory}:
\begin{tscreen}
\begin{verbatim}
case $TERM in
    xterm*)
        PS1="\[\033]0;\u@\h: \w\007\]bash\\$ "
        ;;
    *)
        PS1="bash\\$ "
        ;;
esac
\end{verbatim}
\end{tscreen}

¼Ç×¡ {\ttfamily $\backslash$[...$\backslash$]} µÄÊ¹ÓÃ, ÔÚ¼ÆËãÌâÊ¾³¤¶ÈÊ±,
½«¸æËß {\ttfamily bash} ºöÂÔµô·ÇÁÐÓ¡µÄ¿ØÖÆ×ÖÔª.
·ñÔòÐÐ±à¼­Ö¸Áî½«»áÔÚÒÆ¶¯ÓÎ±êÊ±¸ãÂÒµô.






\subsection{ksh}

{\ttfamily ksh} ¼¸ºõ²»Ìá¹©ÕâÖÖ·½Ê½µÄ¹¦ÄÜº¯Ê½ÓëÑÓÉì¹¦ÄÜ,
Òò´ËÎÒÃÇ±ØÐë²åÈëÒçÎ»×Ö´®µ½ÌáÊ¾×ÖÔªÖÐ, Ê¹ËûÄÜ¶¯Ì¬¸üÐÂ
Õâ¸ö¡õÀý½«²úÉúÖ÷ÌâÎª
{\ttfamily username@hostname: directory} ¶øand a prompt of {\ttfamily ksh\$ }.
\begin{tscreen}
\begin{verbatim}
case $TERM in
    xterm*)
        HOST=`hostname`
        PS1='^[]0;${USER}@${HOST}: ${PWD}^Gksh$ '
        ;;
    *)
        PS1='ksh$ '
        ;;
esac
\end{verbatim}
\end{tscreen}

¶ø, {\ttfamily \$PWD} »á²úÉúÍêÕûµÄÄ¿Â¼Â·¾¶. ÎÒÃÇ¿ÉÒÔ
ÓÃ {\ttfamily \$$\{$...\#\#...$\}$} µÄ·½Ê½ÒÆÈ¥ {\ttfamily \$HOME/} µÄ×ÖÊ×.
ÎÒÃÇÒ²¿ÉÒÔÓÃ {\ttfamily \$$\{$...\%\%...$\}$} µÄ·½·¨À´½ØÈ¥²¿·ÝµÄ hostname:
\begin{tscreen}
\begin{verbatim}
HOST=`hostname`
HOST=${HOST%%.*}
PS1='^[]0;${USER}@${HOST}: ${PWD##${HOME}/}^Gksh$ '
\end{verbatim}
\end{tscreen}

¼Ç×¡ {\ttfamily \^{}[} ¼° {\ttfamily \^{}G} ÔÚÃüÁîÁÐ×Ö´®ÊÇµ¥Ò»×ÖÔª
µÄ {\ttfamily ESC} ¼° {\ttfamily BEL} (ÔÚ emacs µÄ»·¾³ÏÂ¿ÉÒÔÓÃ
{\ttfamily C-q ESC} ¼° {\ttfamily C-q C-g} ÊäÈë).






\subsection{csh}

ÒªÔÚ {\ttfamily csh} Íê³ÉÍ¬ÑùµÄÊÂÕæµÄÓÐµãÀ§ÄÑ, ¶øÎÒÃÇÓÃÏÂÃæµÄ·½Ê½À´½â¾öÎÊÌâ:
\begin{tscreen}
\begin{verbatim}
switch ($TERM)
    case "xterm*":
        set host=`hostname`
        alias cd 'cd \!*; echo -n "^[]0;${user}@${host}: ${cwd}^Gcsh% "'
        breaksw
    default:
        set prompt='csh% '
        breaksw
endsw
\end{verbatim}
\end{tscreen}

Âé·³µÄµØ·½ÊÇÎÒÃÇÒª°Ñ {\ttfamily cd} Õâ¸öÖ¸Áî»¯Éí³É¿ÉËÍ³öÒçÎ»×Ö´®µÄ¹¦ÄÜ.
¼Ç×¡ {\ttfamily \^{}[} ¼° {\ttfamily \^{}G} ÔÚÃüÁîÁÐ×Ö´®ÊÇµ¥Ò»×ÖÔªµÄ
{\ttfamily ESC} ¼° {\ttfamily BEL} (ÔÚ emacs µÄ»·¾³ÏÂ¿ÉÒÔÓÃ
{\ttfamily C-q ESC} ¼° {\ttfamily C-q C-g} ÊäÈë).



¼Ç×¡: ÔÚ²¿·ÝµÄÏµÍ³ {\ttfamily hostname -s} ¿ÉÄÜ»áÈ¡µÃ½Ï¶ÌµÄ
hostname ¶ø²»ÊÇÍêÕûµÄÈ«Ãû. ²¿·ÝÊ¹ÓÃÕßÔÚÓÐ·ûºÅÁ¬½áµÄÄ¿Â¼Ó¦¸Ã»á·¢ÏÖ
{\ttfamily `pwd`} (À¨ÆðÀ´ÒÔÈ·¶¨Ö´ÐÐµÄÊÇ {\ttfamily pwd} Ö¸Áî)
¿ÉÒÔµÃµ½±È {\ttfamily \$cwd} ¸ü¾«È·µÄÂ·¾¶Ãû.








\section{ÏÔÊ¾ÕýÔÚÖ´ÐÐµÄ¹¤×÷Ãû³Æ}

Í¨³£Ê¹ÓÃÕß»áÆô¶¯Ò»¸öÒ»Ö±ÔÚÇ°¾°Ö´ÐÐµÄ¹¤×÷Èç {\ttfamily top}, »ò
Ò»¸ö±à¼­Æ÷, Ò»¸ö email ÓÃ»§¶Ë, µÈµÈ, ²¢Ï£ÍûÕâ¸ö¹¤×÷µÄÃû³Æ±»ÏÔÊ¾ÔÚ
xterm µÄÖ÷ÌâÉÏ. ÕâÊÇ¸öºÜ¼¬ÊÖµÄÎÊÌâÇÒÖ»ÄÜÔÚ {\ttfamily zsh} »·¾³ÏÂ¿ÉÒÔÇáËÉÍê³É.




\subsection{zsh}

{\ttfamily zsh} ÎªÕâÖÖÐèÇóÌá¹©ÁËÒ»¸öºÜÀíÏëµÄÄÚ½¨¹¦ÄÜ:
\begin{tscreen}
\begin{verbatim}
preexec()   Ò»¸öÔÚÃüÁîÖ´ÐÐÇ°Ò»¶¨»á½ÐÓÃµÄ¹¦ÄÜº¯Ê½Ãû
$*,$1,...   ´«ËÍµ½ preexec() µÄ²ÎÊý
\end{verbatim}
\end{tscreen}

Òò´Ë, ÎÒÃÇ¿ÉÒÔÓÃÏÂÃæµÄ·½Ê½°Ñ¹¤×÷Ãû³Æ·Åµ½Ö÷ÌâÉÏ:
\begin{tscreen}
\begin{verbatim}
case $TERM in
    xterm*)
      preexec () {
        print -Pn "\e]0;$*\a"
      }
    ;;
esac
\end{verbatim}
\end{tscreen}

¼Ç×¡: {\ttfamily preexec()} ¹¦ÄÜº¯Ê½ÔÚ {\ttfamily zsh} 3.1.2 °æ³öÏÖ,
Èç¹ûÄãÓÃµÄ°æ±¾½Ï¾ÉÄÇ¾ÍÐèÒª¸üÐÂÒ»ÏÂ.






\subsection{ÆäËûÃüÁî½âÒëÆ÷s}

¶ÔÆäËüÈ±ÉÙ {\ttfamily preexec()} º¯Ê½µÄÃüÁî½âÒëÆ÷, ¾Í²»ÊÇÄÇ÷á¼òµ¥ÁË.
Èç¹ûÈÎºÎÈËÓÐ¡õÀý¿ÉÒÔÍê³ÉÍ¬ÑùµÄ¹¤×÷Çë°ÑËü email ¸ø×÷Õß.






\section{¸½Â¼: ÆäËüÐÍÊ½ÖÕ¶Ë»úµÄÒçÎ»ÐòÁÐ}

Ðí¶àÐÂÊ½µÄÖÕ¶Ë»ú¶¼ÑÜÉú×Ô {\ttfamily xterm} »ò {\ttfamily rxvt}
²¢ÇÒÖ§Ô®ÎÒÃÇËùÊ¹ÓÃµÄÒçÎ»ÐòÁÐ. Ä³Ð©×¨ÀûµÄÖÕ¶Ë»úËæÖø¸÷ÖÖ²»Í¬µÄ unix
··ÂôÔò»áÊ¹ÓÃËûÃÇ×Ö¶©µÄÒçÎ»ÐòÁÐ.






\subsection{IBM {\ttfamily aixterm}}

{\ttfamily aixterm} ¿ÉÒÔ±æÊ¶³ö {\ttfamily xterm µÄÒçÎ»ÐòÁÐ}.






\subsection{SGI {\ttfamily wsh}, {\ttfamily xwsh} ¼° {\ttfamily winterm}}

ÕâÀàÖÕ¶Ë»ú»áÉè¶¨ {\ttfamily \$TERM=iris-ansi} ²¢²ÉÓÃÏÂÁÐµÄÒçÎ»ÐòÁÐ:
\begin{itemize}
\item {\ttfamily ESCP1.y{\itshape string\/}ESC$\backslash$        Éè¶¨ÊÓ´°Ö÷ÌâÎª {\itshape string\/}}
\item {\ttfamily ESCP3.y{\itshape string\/}ESC$\backslash$        Éè¶¨Í¼Ê¾Ö÷ÌâÎª {\itshape string\/}}
\end{itemize}

¶ø {\ttfamily xwsh} ÍêÕûµÄÒçÎ»ÐòÁÐ¿ÉÒÔ²Î¿¼ {\ttfamily xwsh(1G)} µÄÊ¹ÓÃËµÃ÷.



Irix µÄÖÕ¶Ë»úÖ§Ô® {\ttfamily xterm} ¸÷±ðÉè¶¨ÊÓ´°ÓëÍ¼Ê¾Ö÷ÌâµÄ¹¦ÄÜ,
µ«²»ÄÜÁ½Õß¶¼Éè¶¨.






\subsection{Sun {\ttfamily cmdtool} ¼° {\ttfamily shelltool}}

{\ttfamily cmdtool} ¼° {\ttfamily shelltool} »áÉè¶¨ {\ttfamily \$TERM=sun-cmd} 
²¢²ÉÓÃÏÂÁÐµÄÒçÎ»ÐòÁÐ:
\begin{itemize}
\item {\ttfamily ESC]l{\itshape string\/}ESC$\backslash$    Éè¶¨ÊÓ´°Ö÷ÌâÎª {\itshape string\/}}
\item {\ttfamily ESC]L{\itshape string\/}ESC$\backslash$    Éè¶¨Í¼Ê¾Ö÷ÌâÎª {\itshape string\/}}
\end{itemize}

ÕâÐ©ÕæµÄÊÇºÜ¿ÉÅÂµÄ³ÌÊ½: ¾¡Á¿±ðÊ¹ÓÃ.






\subsection{CDE {\ttfamily dtterm}}

{\ttfamily dtterm} »áÉè¶¨ {\ttfamily \$TERM=dtterm}, ËÆºõÊÇ¿ÉÒÔÊ¶±ð³ö±ê×¼µÄ
{\ttfamily xterm} ÒçÎ»ÐòÁÐ¼° Sun {\ttfamily cmdtool} µÄÒçÎ»ÐòÁÐ
(ÔÚ Solaris 2.5.1, Digital Unix 4.0, HP-UX 10.20 ²âÊÔ¹ý).






\subsection{HPterm}

{\ttfamily hpterm} »áÉè¶¨ {\ttfamily \$TERM=hpterm} ²¢²ÉÓÃÏÂÁÐµÄÒçÎ»ÐòÁÐ:
\begin{itemize}
\item {\ttfamily ESC\&f0k{\itshape length\/}D{\itshape string\/}   Éè¶¨ÊÓ´°Ö÷ÌâÎª³¤ {\itshape length\/} µÄ {\itshape string\/}}
\item {\ttfamily ESC\&f-1k{\itshape length\/}D{\itshape string\/}  Éè¶¨Í¼Ê¾Ö÷ÌâÎª³¤ {\itshape length\/} µÄ {\itshape string\/}}
\end{itemize}




Ò»¸ö¼òµ¥µÄ C ÓïÑÔµÄ³ÌÊ½ÓÃÀ´¼ÆËã³¤¶È²¢»ØÓ¦×Ö´®, ÈçÏÂ:
\begin{tscreen}
\begin{verbatim}
#include <string.h>
int main(int argc, char *argv[])
{
    printf("\033&f0k%dD%s", strlen(argv[1]), argv[1]);
    printf("\033&f-1k%dD%s", strlen(argv[1]), argv[1]);
    return(0);
}
\end{verbatim}
\end{tscreen}




ÎÒÃÇÒ²¿ÉÒÔÐ´Ò»¸öÐ¡µÄÃüÁî½Å±¾³ÌÐò, ÓÃ {\ttfamily \$$\{$\#string$\}$}
({\ttfamily zsh}, {\ttfamily bash}, {\ttfamily ksh}) »ò {\ttfamily \$$\{$\%string$\}$}
({\ttfamily tcsh)} µÄÑÓÉì¹¦ÄÜÀ´ÕÒ³ö×Ö´®³¤¶È. ÒÔÏÂ¿ÉÓÃÔÚ {\ttfamily zsh}:
\begin{tscreen}
\begin{verbatim}
case $TERM in
    hpterm)
        str="\e]0;%n@%m: %~\a"
        precmd () {print -Pn "\e&f0k${#str}D${str}"}
        precmd () {print -Pn "\e&f-1k${#str}D${str}"}
        ;;
esac
\end{verbatim}
\end{tscreen}











\section{¸½Â¼: ÆäËüÓïÑÔµÄ¡õÀý}

Ð´Ò»¸öÐ¡³ÌÊ½ÀûÓÃ {\ttfamily xterm} µÄÒçÎ»¹¦ÄÜ°Ñ´«µÝµÄ²ÎÊýµ±³ÉÖ÷Ìâ.
ÒÔÏÂÊÇÒ»Ð©¡õÀý.






\subsection{C}

\begin{tscreen}
\begin{verbatim}
#include <stdio.h>

int main (int argc, char *argv[]) {
  printf("%c]0;%s%c", '\033', argv[1], '\007');
  return(0);
}
\end{verbatim}
\end{tscreen}







\subsection{Perl}

\begin{tscreen}
\begin{verbatim}
#!/usr/bin/perl
print "\033]0;@ARGV\007";
\end{verbatim}
\end{tscreen}









\section{ÃúÐ»Credits}

¸ÐÐ»ÏÂÁÐÖîÎ»Ìá¹©½¨Òé, ÐÞÕý, ¼°¡õÀýÎª±¾ÎÄÔöÉ«²»ÉÙ.



Paul D. Smith {\ttfamily $<$psmith@BayNetworks.COM$>$} ¼°
Christophe Martin {\ttfamily $<$cmartin@ipnl.in2p3.fr$>$}
Á½Î»Ö¸³öÔÚ {\ttfamily bash} {\ttfamily \$PROMPT\_COMMAND} ÖÐÎÒÒýÊöµÄ´íÎó²¿·Ý.
ÕýÈ·µÄ·½·¨±ä»¯ {\itshape ÊÇ\/} ¶¯Ì¬Õ¹¿ªµÄ.



Paul D. Smith {\ttfamily $<$psmith@BayNetworks.COM$>$}
½¨ÒéÔÚ {\ttfamily bash} ÖÐÊ¹ÓÃ {\ttfamily $\backslash$[...$\backslash$]}
ÒÔÕûºÏ²»ÄÜÏÔÊ¾µÄ×ÖÔª.



Christophe Martin {\ttfamily $<$cmartin@ipnl.in2p3.fr$>$}
Ìá¹© {\ttfamily ksh} µÄ½â¾ö·½·¨.



Keith Turner {\ttfamily $<$keith@silvaco.com$>$}
Ìá¹©¸ø Sun µÄ {\ttfamily cmdtool} ¼° {\ttfamily shelltool} Ê¹ÓÃµÄÒçÎ»ÐòÁÐ.



Jean-Albert Ferrez {\ttfamily $<$ferrez@dma.epfl.ch$>$}
Ö¸³öÔÚ "{\ttfamily PWD}" ¼° "{\ttfamily \$PWD}" ÏàÃ¬¶ÜÖ®´¦,
¼° "{\ttfamily $\backslash$}" Óë "{\ttfamily $\backslash$$\backslash$}" µÄÓÃ·¨.



Bob Ellison {\ttfamily $<$papillo@hpellis.fc.hp.com$>$} ¼°
Jim Searle {\ttfamily $<$jims@broadcom.com$>$} ²âÊÔÔÚ HP-UX ÏÂµÄ {\ttfamily dtterm}.



Teng-Fong Seak {\ttfamily $<$seak@drfc.cad.cea.fr$>$} ½¨ÒéÓÃ
{\ttfamily -s} Ñ¡ÏîÒÔ {\ttfamily hostname}, Ê¹ÓÃ {\ttfamily `pwd`}, ÒÔ¼°
ÔÚ {\ttfamily csh} ÏÂÊ¹ÓÃ {\ttfamily echo} .



Trilia {\ttfamily $<$trilia@nmia.com$>$} ½¨Òé¼ÓÈëÆäËûÓïÑÔµÄÓÃ·¨.



Brian Miller {\ttfamily $<$bmiller@telstra.com.au$>$} ¼ÓÈë
{\ttfamily hpterm} µÄÒçÎ»ÐòÁÐÓë¡õÀý.



Lenny Mastrototaro {\ttfamily $<$lenny@click3x.com$>$} ½âÊÍ
Irix ÖÕ¶Ë»ú»·¾³ÏÂ, ÈçºÎÊ¹ÓÃ xterm ÒçÎ»ÐòÁÐ. 



Paolo Supino {\ttfamily $<$paolo@init.co.il$>$} ½¨ÒéÔÚ {\ttfamily bash}
ÃüÁîÁÐÌâÊ¾ÏÂ²ÉÓÃ {\ttfamily $\backslash$$\backslash$\$}.



\end{document}
