use udev rule to update battery

Changed files
+20 -23
modules
personal
home
i3blocks
wm
scripts
-2
modules/personal/home/i3blocks/battery
···
fi
echo "$label $capacity%"
-
-
# udevadm monitor -s=power_supply
···
fi
echo "$label $capacity%"
+9 -20
modules/personal/home/wm/scripts/bat_monitor.sh
···
#!/usr/bin/env sh
-
while :
-
do
-
echo "$(date -Ins) $(acpi -b)"\
-
| tee -a ~/.bat_hist\
-
| awk -F'[,:%]' '{print $6; print $7}' | {
-
read -r status
-
read -r capacity
-
#if [ "$status" = Charging -o "$status" = Full ]; then
-
# ~/.config/sway/scripts/swayidle_lock.sh
-
#fi
-
if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
-
logger "Critical battery threshold"
-
systemctl hibernate
-
elif [ "$status" = Discharging -a "$capacity" -lt 10 ]; then
-
notify-send "warning: battery at $capacity%"
-
fi
-
}
-
sleep 60
-
done
-
···
#!/usr/bin/env sh
+
capacity=$1
+
status=$2
+
if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
+
logger "Critical battery threshold"
+
systemctl hibernate
+
elif [ "$status" = Discharging -a "$capacity" -lt 10 ]; then
+
notify-send "warning: battery at $capacity%"
+
fi
+
pkill -RTMIN+2 i3blocks
+11 -1
modules/personal/laptop.nix
···
-
{ pkgs, config, lib, ... }:
let cfg = config.personal; in
{
···
kanshi
acpi
];
};
}
···
+
{ pkgs, config, lib, self, ... }:
let cfg = config.personal; in
{
···
kanshi
acpi
];
+
+
services.udev.extraRules =
+
let bat-monitor = pkgs.writeTextFile {
+
name = "bat_monitor";
+
text = builtins.readFile ./home/wm/scripts/bat_monitor.sh;
+
executable = true;
+
destination = "/bat_monitor.sh";
+
}; in ''
+
ACTION=="change", SUBSYSTEM=="power_supply", RUN+="${pkgs.bash}/bin/bash ${bat-monitor}/bat_monitor.sh '%s{capacity}' '%s{status}'"
+
'';
};
}