old-www/HOWTO/Bash-Prompt-HOWTO/c679.html

245 lines
3.9 KiB
HTML

<HTML
><HEAD
><TITLE
>Prompt Code Snippets</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Bash Prompt HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE='A "Proof of Concept" Example'
HREF="x672.html"><LINK
REL="NEXT"
TITLE="Built-in Escape Sequences"
HREF="x686.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Bash Prompt HOWTO: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x672.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x686.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="AEN679"
></A
>Chapter 11. Prompt Code Snippets</H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
>11.1. <A
HREF="x686.html"
>Built-in Escape Sequences</A
></DT
><DT
>11.2. <A
HREF="x690.html"
>Date and Time</A
></DT
><DT
>11.3. <A
HREF="x700.html"
>Counting Files in the Current Directory</A
></DT
><DT
>11.4. <A
HREF="x711.html"
>Total Bytes in the Current Directory</A
></DT
><DT
>11.5. <A
HREF="x721.html"
>Checking the Current TTY</A
></DT
><DT
>11.6. <A
HREF="x733.html"
>Stopped Jobs Count</A
></DT
><DT
>11.7. <A
HREF="x746.html"
>Load</A
></DT
><DT
>11.8. <A
HREF="x758.html"
>Uptime</A
></DT
><DT
>11.9. <A
HREF="x771.html"
>Number of Processes</A
></DT
><DT
>11.10. <A
HREF="x783.html"
>Controlling the Size and Appearance of $PWD</A
></DT
><DT
>11.11. <A
HREF="x794.html"
>Laptop Power</A
></DT
><DT
>11.12. <A
HREF="x799.html"
>Having the Prompt Ignored on Cut and Paste</A
></DT
><DT
>11.13. <A
HREF="x806.html"
>New Mail</A
></DT
><DT
>11.14. <A
HREF="x810.html"
>Prompt Beeps After Long-Running Commands</A
></DT
></DL
></DIV
><P
>This section shows how to put various pieces of information into the Bash
prompt. There are an infinite number of things that could be put in your
prompt. Feel free to send me examples, I'll try to include what I think
will be most widely used. If you have an alternate way to retrieve a piece
of information here, and feel your method is more efficient, please contact
me. It's easy to write bad code, I do it often, but it's great to write
elegant code, and a pleasure to read it. I manage it every once in a
while, and would love to have more of it to put in here.&#13;</P
><P
>To incorporate shell code in prompts, it has to be escaped. Usually, this
will mean putting it inside <TT
CLASS="USERINPUT"
><B
>\$(&#60;command&#62;)</B
></TT
> so
that the output of <TT
CLASS="USERINPUT"
><B
>command</B
></TT
> is substituted each time
the prompt is generated.&#13;</P
><P
>Please keep in mind that I develop and test this code on a single user
900 MHz Athlon with 256 meg of RAM, so the delay generated by these code
snippets doesn't usually mean much to me. To help with this, I recently
assembled a 25 MHz 486 SX with 16 meg of RAM, and you will see the output
of the "time" command for each snippet to indicate how much of a delay it
causes on a slower machine.&#13;</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x672.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x686.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>A "Proof of Concept" Example</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Built-in Escape Sequences</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>