All of my important config files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
970 B

7 years ago
  1. #!/bin/bash
  2. # modified from http://ficate.com/blog/2012/10/15/battery-life-in-the-land-of-tmux/
  3. HEART='♥ '
  4. if [[ `uname` == 'Linux' ]]; then
  5. current_charge=$(cat /proc/acpi/battery/BAT1/state | grep 'remaining capacity' | awk '{print $3}')
  6. total_charge=$(cat /proc/acpi/battery/BAT1/info | grep 'last full capacity' | awk '{print $4}')
  7. else
  8. battery_info=`ioreg -rc AppleSmartBattery`
  9. current_charge=$(echo $battery_info | grep -o '"CurrentCapacity" = [0-9]\+' | awk '{print $3}')
  10. total_charge=$(echo $battery_info | grep -o '"MaxCapacity" = [0-9]\+' | awk '{print $3}')
  11. fi
  12. charged_slots=$(echo "((($current_charge/$total_charge)*10)/3)+1" | bc -l | cut -d '.' -f 1)
  13. if [[ $charged_slots -gt 3 ]]; then
  14. charged_slots=3
  15. fi
  16. echo -n '#[fg=colour196]'
  17. for i in `seq 1 $charged_slots`; do echo -n "$HEART"; done
  18. if [[ $charged_slots -lt 3 ]]; then
  19. echo -n '#[fg=colour254]'
  20. for i in `seq 1 $(echo "3-$charged_slots" | bc)`; do echo -n "$HEART"; done
  21. fi