gempir

battery

Jan 9th, 2021
1,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.38 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3.  
  4. VOLTAGE_FILE=${1:-"/sys/class/power_supply/hidpp_battery_1/voltage_now"}    
  5.  
  6.  
  7. declare -A LEVELS
  8.  
  9. LEVELS["4186"]="100"                   
  10. # 4156  99%
  11. # ... more shit                            
  12. LEVELS["35"]="0"   
  13.  
  14. VOLTAGE=`cat $VOLTAGE_FILE`
  15. VOLTAGE=${VOLTAGE::-3}
  16.  
  17. for i in "${!LEVELS[@]}"
  18. do
  19.     if [ "$VOLTAGE" -ge "$i" ]; then
  20.         echo "$LEVELS[$i]"
  21.         break
  22.     fi
  23. done
Advertisement
Add Comment
Please, Sign In to add comment