Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- ##############################
- # Battery Status refactoring #
- ##############################
- export DISPLAY=:0.0
- get_ac_adapter_status() {
- echo $(acpi -a | cut -d' ' -f3 | cut -d- -f1)
- }
- get_battery_level() {
- echo $(acpi -b | grep -P -o '[0-9]+(?=%)')
- }
- notify_user() {
- local message="$1"
- local icon="$2"
- notify-send -u critical "$message" -i "$icon"
- }
- charge_above_threshold() {
- local threshold="$1"
- while true; do
- AC_ADAPTER=$(get_ac_adapter_status)
- BATTERY_LEVEL=$(get_battery_level)
- if [ "$AC_ADAPTER" == "off" ]; then
- break
- elif [ "$BATTERY_LEVEL" -ge "$threshold" ]; then
- notify_user "Desconecte o adaptador de energia! Nível da bateria: ${BATTERY_LEVEL}% (acima de $threshold%)" "battery-full-charged"
- fi
- done
- }
- charge_below_threshold() {
- local threshold="$1"
- while true; do
- AC_ADAPTER=$(get_ac_adapter_status)
- BATTERY_LEVEL=$(get_battery_level)
- if [ "$AC_ADAPTER" == "on" ]; then
- break
- elif [ "$BATTERY_LEVEL" -lt "$threshold" ]; then
- notify_user "Conecte o adaptador de energia! Nível da bateria: ${BATTERY_LEVEL}% (abaixo de $threshold%)" "battery-caution"
- fi
- done
- }
- while true; do
- AC_ADAPTER=$(get_ac_adapter_status)
- BATTERY_LEVEL=$(get_battery_level)
- if [ "$AC_ADAPTER" == "on" ]; then
- charge_above_threshold 75
- else
- charge_below_threshold 25
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement