Skip to content

Commit

Permalink
Update: Better battery script (using upower instead of acpi).
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyitdev committed Jun 22, 2022
1 parent 0f8a50a commit 9f47919
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions scripts/battery
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ done
dir_icons="/usr/local/bin/icons"

# notify when below this percentage
warning_level=15
warning_level=20

# how often to check battery status, in minutes
check_interval=1

while true; do
battery_level=$(acpi -b \
| cut -d, -f2 | cut --characters=2,3,4 \
| sed 's/%//g')
charging=$(acpi -b | grep -c "charging")

# when battery is low, and not already charging
if [ "$battery_level" -lt "$warning_level" ] &&
[ "$charging" -eq 0 ]
battery_level=$(upower -i $(upower -e | grep BAT) | grep -E "percentage" | sed 's/[^0-9]//g')
discharging=$(upower -i $(upower -e | grep BAT) | grep -E "state" | grep -c "discharging")
time_to_empty=$(upower -i $(upower -e | grep BAT) | grep -E "time to empty" | sed 's/[^0-9,.]//g')

# check if battery is low and discharging
if [ "$battery_level" -lt "$warning_level" ] && [ "$discharging" -eq 1 ]
then
dunstify -a "Battery" \
"Low battery: ${battery_level}%" \
"Battery is running low" \
"Battery is low ($time_to_empty minutes left)" \
-r 100 \
-i $dir_icons/battery.svg
fi

sleep ${check_interval}m
done
done

0 comments on commit 9f47919

Please sign in to comment.