Skip to content

@starenka /battery_status.sh
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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

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
Something went wrong with that request. Please try again.