Skip to content

Instantly share code, notes, and snippets.

@supertunaman
Created March 10, 2011 23:46
Show Gist options
  • Save supertunaman/865198 to your computer and use it in GitHub Desktop.
Save supertunaman/865198 to your computer and use it in GitHub Desktop.
A battery life indicator that fits nicely in a $PS1
#!/bin/bash
endcolor="\033[1;31m"
innercolor="\033[1;33m"
nocolor="\033[0m"
charge_now=$(cat /sys/class/power_supply/BAT0/charge_now)
charge_full=$(cat /sys/class/power_supply/BAT0/charge_full)
percent=$(echo "scale=2; ( $charge_now / $charge_full ) * 100" | bc | sed 's/\(.*\).../\1/g')
bars=$(echo "($percent / 20) + 1" | bc)
#echo -ne "$endcolor[$innercolor"
for i in {1..5}
do
if [ $bars -gt $i ] || [ $bars -eq $i ] && [ $percent -gt 5 ]
then
echo -n "|"
else
echo -n " "
fi
done
#echo -ne "$endcolor}$nocolor"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment