Created
October 22, 2011 00:59
-
-
Save starenka/1305375 to your computer and use it in GitHub Desktop.
show battery status, you can use it in your prompt f.e like this PS1="[\$(~/bin/battery_status.sh)] \[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NON='\033[00m' | |
BLD='\033[01m' | |
BNK='\e[5m' | |
NBK='\e[m' | |
RED='\033[01;31m' | |
GRN='\033[01;32m' | |
YEL='\033[01;33m' | |
declare -A states | |
states['Charging']="+" | |
states['Discharging']="-" | |
states['Unknown']="~" | |
curr=`cat /sys/class/power_supply/BAT0/energy_now` | |
full=`cat /sys/class/power_supply/BAT0/energy_full` | |
status=`cat /sys/class/power_supply/BAT0/status` | |
ratio=$((100*$curr/$full)) | |
colour="$BLD$BNK$RED" | |
if [ "$ratio" -gt "10" ]; then colour="$BLD$RED"; fi | |
if [ "$ratio" -gt "15" ]; then colour="$YEL"; fi | |
if [ "$ratio" -gt "60" ]; then colour="$GRN"; fi | |
echo -e "$colour${states[$status]}$ratio%$NON$NBK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use ACPI for battery stats:
visgean@rewitaqia:~$ acpi
Battery 0: Discharging, 93%, 02:46:44 remaining