Created
March 10, 2011 23:46
-
-
Save supertunaman/865198 to your computer and use it in GitHub Desktop.
A battery life indicator that fits nicely in a $PS1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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