Added battery notify (currently don't work)
I'm fighting with udev to get it work properly.
This commit is contained in:
parent
b28d614193
commit
3433f4a7e2
|
@ -13,6 +13,6 @@ in with lib; {
|
|||
powerManagement.powertop.enable = true;
|
||||
services.upower.enable = true;
|
||||
|
||||
environment.systemPackages = with pkgs; [ powertop ];
|
||||
environment.systemPackages = with pkgs; [ powertop tpacpi-bat ];
|
||||
};
|
||||
}
|
||||
|
|
58
pkgs/battery-notify.nix
Normal file
58
pkgs/battery-notify.nix
Normal file
|
@ -0,0 +1,58 @@
|
|||
{ pkgs, ... }:
|
||||
let
|
||||
xpub = pkgs.fetchurl {
|
||||
url =
|
||||
"https://raw.githubusercontent.com/Ventto/xpub/f2eadaaf9c8539abbd46b23c0b2f6d93d2ebd658/src/xpub.sh";
|
||||
sha256 = "sha256-88t9lr6DxrWrg6E4YsWGzYV9/GbRgwLafAklXHObqsI=";
|
||||
executable = true;
|
||||
};
|
||||
in pkgs.writeShellScriptBin "battery-notify" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
|
||||
# ''${DISPLAY:=":0"}
|
||||
#: $\{XUSER:=":james"\}
|
||||
|
||||
touch /tmp/battery-notify
|
||||
echo "display:$DISPLAY" >> /tmp/battery-notify
|
||||
echo "tty:$TTY" >> /tmp/battery-notify
|
||||
echo "XUSER:$XUSER" >> /tmp/battery-notify
|
||||
echo "DBUS_SESSION_BUS_ADDRESS:$DBUS_SESSION_BUS_ADDRESS" >> /tmp/battery-notify
|
||||
|
||||
export $(${xpub}) ;
|
||||
function last_chance {
|
||||
if [ -f /tmp/last_chance ] ; then
|
||||
echo "There already exist another processing doing this. Aborting."
|
||||
exit
|
||||
else
|
||||
${pkgs.coreutils}/bin/touch /tmp/last_chance
|
||||
fi
|
||||
|
||||
countdown=30
|
||||
while [[ $(${pkgs.coreutils}/bin/cat /sys/class/power_supply/AC/online) -eq 0 ]] ; do
|
||||
if [[ countdown -gt 0 ]] ; then
|
||||
${pkgs.libnotify}/bin/notify-send -h string:x-canonical-private-synchronous:battery -u critical " Critical Battery - Suspension imminent." "You have $countdown seconds." ; sleep 1
|
||||
let "countdown=countdown-1"
|
||||
else
|
||||
${pkgs.libnotify}/bin/notify-send -h string:x-canonical-private-synchronous:battery -u low " Critical Battery" "PlaceHolder"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
${pkgs.coreutils}/bin/rm /tmp/last_chance
|
||||
}
|
||||
|
||||
case $1 in
|
||||
charging)
|
||||
${pkgs.libnotify}/bin/notify-send -h string:x-canonical-private-synchronous:battery -u low " Power Connected" "Battery at $(${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity)%";;
|
||||
discharging)
|
||||
${pkgs.libnotify}/bin/notify-send -h string:x-canonical-private-synchronous:battery -u low " Power Disconnected" "Battery at $(${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity)%";;
|
||||
warn)
|
||||
${pkgs.libnotify}/bin/notify-send -h string:x-canonical-private-synchronous:battery -u normal " Discharging" "Battery at $(${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity)%";;
|
||||
danger)
|
||||
${pkgs.libnotify}/bin/notify-send -h string:x-canonical-private-synchronous:battery -u critical " Low Battery" "Battery at $(${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity)%. Will suspend soon.";;
|
||||
ohfuck)
|
||||
last_chance ;;
|
||||
*)
|
||||
echo "invalid command" ;;
|
||||
esac
|
||||
''
|
|
@ -1,5 +1,6 @@
|
|||
self: super: {
|
||||
brightness-sh = super.callPackage ./brightness.nix { inherit super; };
|
||||
battery-notify = super.callPackage ./battery-notify.nix { inherit super; };
|
||||
sway-entry = super.callPackage ./sway-entry.nix { inherit super; };
|
||||
volume-sh = super.callPackage ./volume.nix { inherit super; };
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user