Initial commit
This commit is contained in:
22
config/hypr/scripts/suspend_on_battery
Executable file
22
config/hypr/scripts/suspend_on_battery
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Find all battery devices (BAT0, BAT1, etc.)
|
||||
BATTERY_DEVICES=$(upower -e | grep 'BAT')
|
||||
ON_BATTERY=false
|
||||
|
||||
# Iterate through all detected batteries
|
||||
for DEVICE in $BATTERY_DEVICES; do
|
||||
# Get the state for the current battery device
|
||||
STATE=$(upower -i $DEVICE | grep "state" | awk '{print $2}')
|
||||
|
||||
# Check if the state is 'discharging' for ANY battery
|
||||
if [ "$STATE" = "discharging" ]; then
|
||||
ON_BATTERY=true
|
||||
break # Exit the loop as soon as one is found to be discharging
|
||||
fi
|
||||
done
|
||||
|
||||
# Check the final condition and suspend if true
|
||||
if $ON_BATTERY; then
|
||||
systemctl suspend
|
||||
fi
|
||||
Reference in New Issue
Block a user