Skip to content

Instantly share code, notes, and snippets.

@starenka
Created October 22, 2011 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starenka/1305375 to your computer and use it in GitHub Desktop.
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"
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"
@Visgean
Copy link

Visgean commented Nov 1, 2011

I use ACPI for battery stats:
visgean@rewitaqia:~$ acpi
Battery 0: Discharging, 93%, 02:46:44 remaining

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment