Initial commit
This commit is contained in:
commit
b79d352847
37 changed files with 2191 additions and 0 deletions
47
home/low-battery-notify/default.nix
Normal file
47
home/low-battery-notify/default.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
options = {
|
||||
custom.low-battery-notify.enable = lib.mkEnableOption "Enable low battery notification";
|
||||
};
|
||||
config = lib.mkIf config.custom.low-battery-notify.enable {
|
||||
home.packages = with pkgs; [
|
||||
python3
|
||||
];
|
||||
systemd.user = {
|
||||
services = {
|
||||
low-battery-notify = {
|
||||
Unit = {
|
||||
Description = "Low battery notify";
|
||||
};
|
||||
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "/home/flygrounder/.local/share/scripts/low-battery-notify.py";
|
||||
};
|
||||
};
|
||||
};
|
||||
timers = {
|
||||
low-battery-notify = {
|
||||
Unit = {
|
||||
Description = "test";
|
||||
};
|
||||
|
||||
Timer = {
|
||||
OnUnitActiveSec = "10m";
|
||||
OnBootSec = "10m";
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = [ "timers.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
xdg.dataFile = {
|
||||
low-battery-notify = {
|
||||
source = ./script.py;
|
||||
target = "scripts/low-battery-notify.py";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
11
home/low-battery-notify/script.py
Executable file
11
home/low-battery-notify/script.py
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
output = subprocess.check_output(["acpi", "-b"]).decode()
|
||||
m = re.match(r'.*Discharging, (\d+)%', output)
|
||||
if m is None:
|
||||
exit()
|
||||
charge = int(m.group(1))
|
||||
if charge <= 20:
|
||||
subprocess.run(["dunstify", "-u", "critical", f"Низкий уровень заряда: {charge}%"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue