removed batsignal. Used a bash script for battery notifications

This commit is contained in:
Tomas Rivera
2026-02-26 18:11:46 +01:00
parent 02b6df2a56
commit ae3d890e87
2 changed files with 73 additions and 1 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ home.stateVersion = "25.11"; # Please read the comment before changing.
home.packages = [ home.packages = [
#scritps #scritps
(pkgs.callPackage ../../modules/scripts/dontkillsteam.nix {}) (pkgs.callPackage ../../modules/scripts/dontkillsteam.nix {})
(pkgs.callPackage ../../modules/scripts/batterynotify.nix {})
# # Adds the 'hello' command to your environment. It prints a friendly # # Adds the 'hello' command to your environment. It prints a friendly
# # "Hello, world!" when run. # # "Hello, world!" when run.
# pkgs.hello # pkgs.hello
+72
View File
@@ -0,0 +1,72 @@
{ writeShellApplication
, libnotify
, systemd
}:
writeShellApplication {
name = "custom-batterynotify";
runtimeInputs = [
libnotify # provides notify-send
systemd # provides systemctl
];
text = ''
set -euo pipefail
LOW="''${BATTERY_LOW_THRESHOLD:-20}"
CRITICAL="''${BATTERY_CRITICAL_THRESHOLD:-5}"
FULL="''${BATTERY_FULL_THRESHOLD:-95}"
INTERVAL="''${BATTERY_INTERVAL:-30}"
ACTION="''${BATTERY_CRITICAL_ACTION:-systemctl suspend}"
notify() {
notify-send -a "Battery" -u "$1" "$2" "$3"
}
get_info() {
total=0
count=0
for bat in /sys/class/power_supply/BAT*; do
[ -f "$bat/capacity" ] || continue
capacity=$(<"$bat/capacity")
status=$(<"$bat/status")
total=$((total + capacity))
count=$((count + 1))
done
[ "$count" -gt 0 ] || exit 0
percentage=$((total / count))
}
last_state=""
while true; do
get_info
state="$status-$percentage"
if [[ "$status" == "Discharging" && "$percentage" -le "$CRITICAL" ]]; then
notify critical "Battery Critically Low" "$percentage% suspending."
$ACTION
elif [[ "$status" == "Discharging" && "$percentage" -le "$LOW" ]]; then
if [[ "$last_state" != "low" ]]; then
notify normal "Battery Low" "$percentage% remaining."
last_state="low"
fi
elif [[ "$status" != "Discharging" && "$percentage" -ge "$FULL" ]]; then
if [[ "$last_state" != "full" ]]; then
notify normal "Battery Full" "$percentage% unplug charger."
last_state="full"
fi
else
last_state=""
fi
sleep "$INTERVAL"
done
'';
}