⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch07_06.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 7] 7.6 Session Information in Your Terminal's Status Line </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:33:47Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch07_01.htm"TITLE="7. Setting Your Shell Prompt"><LINKREL="prev"HREF="ch07_05.htm"TITLE="7.5 Multiline Shell Prompts "><LINKREL="next"HREF="ch07_07.htm"TITLE='7.7 A "Menu Prompt&quot; for Naive Users'></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch07_05.htm"TITLE="7.5 Multiline Shell Prompts "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 7.5 Multiline Shell Prompts "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 7<BR>Setting Your Shell Prompt</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch07_07.htm"TITLE='7.7 A "Menu Prompt&quot; for Naive Users'><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT='Next: 7.7 A "Menu Prompt&quot; for Naive Users'BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1310">7.6 Session Information in Your Terminal's Status Line </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-6862"></A>Some people don't like to put the current directory, hostname, etc.into their prompts because it makes the screen look cluttered to them.Here's another idea.  If your terminal or window system has a statusline or title bar, you might be able to put the information there.That's nice because you'll be able to see the information while yourun programs.  The bad side is that the information can getout-of-date if you use a command that takes you to another host ordirectory without updating the status line.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-6866"></A><ACLASS="indexterm"NAME="AUTOID-6869"></A><ACLASS="indexterm"NAME="AUTOID-6872"></A><ACLASS="indexterm"NAME="AUTOID-6875"></A>When you <EMCLASS="emphasis">cd</EM>, an alias uses the <EMCLASS="emphasis">echo</EM> command to writespecial<SPANCLASS="link">escape sequences (<ACLASS="linkend"HREF="ch05_08.htm"TITLE="Terminal Escape Sequences ">5.8</A>)</SPAN>(terminal commands) to the terminal or window.</P><PCLASS="para">Here's a <EMCLASS="emphasis">cd</EM> alias and other commands for your <EMCLASS="emphasis">.cshrc</EM> file.If I were logged in to <EMCLASS="emphasis">www.jpeek.com</EM> in the directory <EMCLASS="emphasis">/home/jpeek</EM>,this alias would put:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">www:/home/jpeek</PRE></BLOCKQUOTE></P><PCLASS="para">in the status area.Of course, you can change the format of the status line.Change the command string below, <CODECLASS="literal">${host:h}:${cwd}</CODE>, to do whatyou need.</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch45_35.htm"TITLE="45.35 Using a Control Character in a Script ">echo...033</A> <ACLASS="co"HREF="ch44_09.htm"TITLE="44.9 Testing Your Success ">&amp;&amp;</A> &#13;</PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">set e=&quot;`echo -n x | tr x \\033`&quot;   # Make an ESCape characterset host=`uname -n`# Puts $host and $cwd in VT102 status line. Escape sequences are:# ${e}7 = save cursor position, ${e}[25;1f = go to start of status# line (line 25), ${e}[0K = erase line, ${e}8 = restore cursoralias cd 'chdir \!* &amp;&amp; \\   echo -n &quot;${e}7${e}[25;1f${e}[0K    ${host:h}:${cwd}${e}8&quot;'</PRE></TD></TR></TABLE></P><PCLASS="para">If you always use a VT102-type terminal (and many people do), that aliaswill work fine.If you use a different terminal, read its manual or its<SPANCLASS="link"><EMCLASS="emphasis">termcap</EM>/<EMCLASS="emphasis">terminfo</EM> entry (<ACLASS="linkend"HREF="ch41_11.htm"TITLE="How termcap and terminfo Describe Terminals ">41.11</A>)</SPAN>and find the escapesequences that work for it.</P><PCLASS="para">People who use more than one type of terminal, that aren't allVT102-compatible, can add a<SPANCLASS="link"><EMCLASS="emphasis">case</EM> (<ACLASS="linkend"HREF="ch44_05.htm"TITLE="Test String Values with Bourne Shell case ">44.5</A>)</SPAN>or<SPANCLASS="link"><EMCLASS="emphasis">switch</EM> (<ACLASS="linkend"HREF="ch47_06.htm"TITLE="Quick Reference: C Shell switch Statement ">47.6</A>)</SPAN>to test theterminal type and use a <EMCLASS="emphasis">cd</EM> alias written for that terminal.(The alias can also put the status information in the shell prompt onterminals that don't have a status line.)But you might have some trouble:if the alias is defined in your <EMCLASS="emphasis">.cshrc</EM> file but your terminal typeis set in your <EMCLASS="emphasis">.login</EM> file, the terminal type may not be setuntil after the alias has been read.There are<SPANCLASS="link">workarounds (<ACLASS="linkend"HREF="ch02_07.htm"TITLE="C Shell Setup Files Aren't Read When You Want Them to Be? ">2.7</A>)</SPAN>.</P><PCLASS="para">The status line can also get out of sync with reality if you use<SPANCLASS="link">remote logins (<ACLASS="linkend"HREF="ch01_33.htm"TITLE="UNIX Networking and Communications ">1.33</A>)</SPAN>,<SPANCLASS="link">subshells (<ACLASS="linkend"HREF="ch38_04.htm"TITLE="Subshells ">38.4</A>)</SPAN>,and other things.These might put a new prompt in the status line but not reset theoriginal prompt when it should be reset.The easiest workaround for this is by using the command below tochange directory to the current directory (<CODECLASS="literal">.</CODE>) andreset the status line:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>cd .</B></CODE></PRE></BLOCKQUOTE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch07_05.htm"TITLE="7.5 Multiline Shell Prompts "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 7.5 Multiline Shell Prompts "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch07_07.htm"TITLE='7.7 A "Menu Prompt&quot; for Naive Users'><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT='Next: 7.7 A "Menu Prompt&quot; for Naive Users'BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">7.5 Multiline Shell Prompts </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">7.7 A "Menu Prompt&quot; for Naive Users</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -