Skip to content

Commit

Permalink
enable low battery level notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe committed Sep 9, 2023
1 parent 673da81 commit f16be8b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions home/overlays/bat-lvl/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
self: super:

{
bat-lvl = self.callPackage ../../scripts/battery-level.nix { };
}
1 change: 1 addition & 0 deletions home/programs/xmonad/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let
${pkgs.pasystray}/bin/pasystray &
${pkgs.blueman}/bin/blueman-applet &
${pkgs.networkmanagerapplet}/bin/nm-applet --sm-disable --indicator &
${pkgs.bat-lvl}/bin/battery-level-check &
megasync &
'';
in
Expand Down
26 changes: 26 additions & 0 deletions home/scripts/battery-level.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ acpi, libnotify, writeShellScriptBin }:

let
xacpi = "${acpi}/bin/acpi";
notify = "${libnotify}/bin/notify-send";
in
writeShellScriptBin "battery-level-check" ''
check_battery_level() {
PERCENT=`${xacpi} | cut -d , -f2`
PERCENT=''${PERCENT%\%}
STATUS=`${xacpi} -a`
if [[ $PERCENT -lt 10 && $STATUS == *"off-line"* ]]; then
${notify} --urgency=critical 'Low battery!' "$PERCENT% left"
fi
}
sleep_pid=0
while true; do
check_battery_level
sleep 60 &
sleep_pid=$!
wait
done
''
4 changes: 2 additions & 2 deletions home/services/dunst/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ in
timeout = 4;
};
urgency_critical = {
background = "#${base0A}";
foreground = "#${base0D}";
background = "#${base00}";
foreground = "#${base05}";
frame_color = "#${base08}";
timeout = 10;
};
Expand Down
1 change: 1 addition & 0 deletions outputs/home-conf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let
neovim-flake.overlays.${system}.default
statix.overlays.default
sxmOverlay
(import ../home/overlays/bat-lvl)
(import ../home/overlays/nautilus)
(import ../home/overlays/ranger)
];
Expand Down

0 comments on commit f16be8b

Please sign in to comment.