Created
December 8, 2013 20:15
-
-
Save bengosney/7863287 to your computer and use it in GitHub Desktop.
Small script the gives you the battery percentage and colours it green when charging and red when discharging. Returns nothing if battery is 100%. I use it in my bash prompt and set the percentage a little lower.
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 | |
max_bat=`cat /sys/class/power_supply/BAT0/charge_full` | |
cur_bat=`cat /sys/class/power_supply/BAT0/charge_now` | |
per_bat=`echo "scale=0; $cur_bat*100/$max_bat" | bc` | |
status=`cat /sys/class/power_supply/BAT0/status | grep Discharging` | |
if [ $per_bat -le 100 ]; then | |
echo -ne "$(tput sgr0)" | |
if [ -z "$status" ];then | |
echo -ne "$(tput setaf 2)" | |
else | |
echo -ne "$(tput setaf 1)" | |
fi | |
echo "${per_bat}%$(tput sgr0)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment