11.11. 笔记本电脑电源

如果你的笔记本电脑安装了 APM,可以尝试以下 PROMPT_COMMAND 来创建一个环境变量${battery}你可以将其添加到你的提示符中。这将指示是否已连接交流电源以及剩余电量百分比。交流电源已连接用“^”表示(表示开启),断开连接用“v”表示,显示在百分比值之前。

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}"
}