Last active
May 28, 2017 11:28
-
-
Save zjrosen1/caa9bea3a7082c42116013694fedee78 to your computer and use it in GitHub Desktop.
wtf
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 | |
HEART='♥' | |
if [[ `uname` == 'Linux' ]]; then | |
current_charge=$(cat /proc/acpi/battery/BAT1/state | grep 'remaining capacity' | awk '{print $3}') | |
total_charge=$(cat /proc/acpi/battery/BAT1/info | grep 'last full capacity' | awk '{print $4}') | |
else | |
battery_info=`ioreg -rc AppleSmartBattery` | |
current_charge=$(echo $battery_info | grep -o '"CurrentCapacity" = [0-9]\+' | awk '{print $3}') | |
total_charge=$(echo $battery_info | grep -o '"MaxCapacity" = [0-9]\+' | awk '{print $3}') | |
fi | |
charged_slots=$(echo "(($current_charge/$total_charge)*10)+1" | bc -l | cut -d '.' -f 1) | |
if [[ $charged_slots -gt 10 ]]; then | |
charged_slots=10 | |
fi | |
echo -n '#[fg=red]' | |
for i in `seq 1 $charged_slots`; do echo -n "$HEART"; done | |
if [[ $charged_slots -lt 10 ]]; then | |
echo -n '#[fg=white]' | |
for i in `seq 1 $(echo "10-$charged_slots" | bc)`; do echo -n "$HEART"; done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment