battery life in bash prompt
2009-5-2 14:0:0 Author: arighi.blogspot.com(查看原文) 阅读量:5 收藏

I've just reconfigured my .bashrc to execute this bash script that allows to show the perentage of battery life at the beginning of the command prompt. Geeze, really nice! :) At this point I can turn off the guidance-power-manager applet and enjoy a faster boot.


#!/bin/bash
GRAY="1;30"
CYAN="0;36"
LIGHT_CYAN="1;36"
LIGHT_BLUE="1;34"
YELLOW="1;33"
WHITE="0;1"
NO_COLOR="0"
LIGHT_RED="1;31"
LIGHT_GREEN="1;32"
BROWN="0;33"

function battery_info()
{
BATT_INFO=$(acpi -b | awk -F', ' '{print $2}')
AC_INFO=$(acpi -aB | awk -F': ' '{print $2}')

if [ $AC_INFO = "off-line" ]; then
BATT_PERC=${BATT_INFO:0:${#BATT_INFO}-1}

if [ $BATT_PERC -ge 75 ]; then
COLOR=$LIGHT_GREEN
elif [ $BATT_PERC -le 25 ]; then
COLOR=$LIGHT_RED
else
COLOR=$YELLOW
fi
else
COLOR=$NO_COLOR
fi
}

PROMPT_COMMAND=battery_info
PS1="\[\033[\$(echo -n \$COLOR)m\]\$(echo -n \$BATT_INFO)\
\[\033[${NO_COLOR}m\] \[email protected]\h:\[\033[${WHITE}m\]\w\[\033[${NO_COLOR}m\]\$ "


文章来源: http://arighi.blogspot.com/2009/05/battery-life-in-bash-prompt.html
如有侵权请联系:admin#unsafe.sh