<HTML ><HEAD ><TITLE >Laptop Power</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Bash Prompt HOWTO" HREF="index.html"><LINK REL="UP" TITLE="Prompt Code Snippets" HREF="c679.html"><LINK REL="PREVIOUS" TITLE="Controlling the Size and Appearance of $PWD" HREF="x783.html"><LINK REL="NEXT" TITLE="Having the Prompt Ignored on Cut and Paste" HREF="x799.html"></HEAD ><BODY CLASS="SECT1" 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="x783.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 11. Prompt Code Snippets</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x799.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="AEN794" ></A >11.11. Laptop Power</H1 ><P >If you have a laptop with APM installed, try the following PROMPT_COMMAND to create an environment variable <TT CLASS="USERINPUT" ><B >${battery}</B ></TT > you can add to your prompt. This will indicate if AC power is connected and percentage power remaining. AC power is indicated by a "^" (for on) and a "v" (for off) before the percentage value. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><FONT COLOR="#000000" ><PRE CLASS="PROGRAMLISTING" >function prompt_command { # As much of the response of the "apm" command as is # necessary to identify the given condition: NO_AC_MESG="AC off" AC_MESG="AC on" APMD_RESPONSE="$(apm)" case ${APMD_RESPONSE} in *${AC_MESG}*) ACstat="^" ;; *${NO_AC_MESG}*) ACstat="v" ;; esac battery="${temp##* }" battery="${ACstat}${battery}" }</PRE ></FONT ></TD ></TR ></TABLE ></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="x783.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="x799.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Controlling the Size and Appearance of $PWD</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c679.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Having the Prompt Ignored on Cut and Paste</TD ></TR ></TABLE ></DIV ></BODY ></HTML >