Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

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"

View battery_status.sh
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

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.