Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. source /home/user/scripts/_vars/global
  4. source /home/user/scripts/_vars/termcolors
  5.  
  6. function check() {
  7.  
  8. # charge level
  9. level=$(</sys/class/power_supply/BAT0/capacity)
  10.  
  11. # battery state
  12. state=$(</sys/class/power_supply/BAT0/status)
  13.  
  14. if [ "$state" != "Full" ] && [ "$state" != "Charging" ]; then
  15.  
  16. if [ "$level" = "40" ] || [ "$level" = "15" ]; then
  17.  
  18. notify low
  19.  
  20. elif [ "$level" = "5" ]; then
  21.  
  22. notify empty
  23.  
  24. /home/user/scripts/desktop/menu battery
  25.  
  26. fi
  27.  
  28. fi
  29.  
  30. }
  31.  
  32. function notify() {
  33.  
  34. _check_notifier
  35.  
  36. # charge level
  37. level=$(</sys/class/power_supply/BAT0/capacity)
  38.  
  39. # battery state status (Full, Discharging, Charging)
  40. state=$(</sys/class/power_supply/BAT0/status)
  41.  
  42. warning=$1
  43.  
  44. if [ "$warning" = "empty" ]; then
  45.  
  46. icon="battery_empty"
  47. urgency="critical"
  48. timeout=$NOTIFY_TIMEOUT_CRITICAL
  49. message="<span foreground=\'$NOTIFY_COLOR_YELLOW\'><b>Battery Empty</b></span>\nCharge: <span foreground=\'${NOTIFY_COLOR_RED}\'><b>${level}%</b></span> (${state})"
  50.  
  51. elif [ "$warning" = "low" ]; then
  52.  
  53. icon="battery_low"
  54. urgency="critical"
  55. timeout=$NOTIFY_TIMEOUT_CRITICAL
  56. message="<span foreground=\'$NOTIFY_COLOR_YELLOW\'><b>Battery Low</b></span>\nCharge: <span foreground=\'${NOTIFY_COLOR_RED}\'><b>${level}%</b></span> (${state})"
  57.  
  58. else
  59.  
  60. icon="battery"
  61. urgency="low"
  62. timeout=$NOTIFY_TIMEOUT_NORMAL
  63. message="<b>Battery</b>\nCharge: <b>${level}%</b> (${state})"
  64.  
  65. fi
  66.  
  67. _send_notification "battery" "$icon" "$urgency" "$timeout" "battery" "$message"
  68.  
  69.  
  70. }
  71.  
  72. function output() {
  73.  
  74. # charge level
  75. level=$(</sys/class/power_supply/BAT0/capacity)
  76.  
  77. # battery state status (Full, Discharging, Charging)
  78. state=$(</sys/class/power_supply/BAT0/status)
  79.  
  80. if [ "$level" = "100" ]; then
  81. levelstring="${COLOR_GREEN}${level}%${COLOR_RESET}"
  82. elif [ "$level" -lt "100" ] && [ "$level" -gt "40" ]; then
  83. levelstring="${COLOR_YELLOW}${level}%${COLOR_RESET}"
  84. else
  85. levelstring="${COLOR_RED}${level}%${COLOR_RESET}"
  86. fi
  87.  
  88. if [ "$state" = "Full" ] || [ "$state" = "Charging" ]; then
  89. statestring="(${COLOR_GREEN}${state}${COLOR_RESET})"
  90. else
  91. statestring="(${COLOR_YELLOW}${state}${COLOR_RESET})"
  92. fi
  93.  
  94. echo "Battery: $levelstring $statestring"
  95.  
  96. }
  97.  
  98. case $1 in
  99. check) check ;;
  100. notify) notify $2 ;;
  101. "") output ;;
  102. *) _invalid_output ;;
  103. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement