public
Created

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"

  • Download Gist
battery_status.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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"

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.