battery.plugin.zsh 700 B

1234567891011121314151617181920
  1. if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
  2. function battery_pct_remaining() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
  3. function battery_time_remaining() { echo $(acpi | cut -f3 -d ',') }
  4. function battery_pct_prompt() {
  5. b=$(battery_pct_remaining)
  6. if [ $b -gt 50 ] ; then
  7. color='green'
  8. elif [ $b -gt 20 ] ; then
  9. color='yellow'
  10. else
  11. color='red'
  12. fi
  13. echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
  14. }
  15. else
  16. error_msg='no battery'
  17. function battery_pct_remaining() { echo $error_msg }
  18. function battery_time_remaining() { echo $error_msg }
  19. function battery_pct_prompt() { echo '' }
  20. fi