diff options
| -rw-r--r-- | .zshrc | 2 | ||||
| -rw-r--r-- | hosts/laptop-nixos/configuration.nix | 23 | ||||
| -rw-r--r-- | hosts/laptop-nixos/home.nix | 3 | ||||
| -rwxr-xr-x | scripts/battery_notifier.sh | 23 |
4 files changed, 50 insertions, 1 deletions
@@ -54,7 +54,7 @@ setopt hist_ignore_dups setopt hist_find_no_dups # Aliases -alias cat='bat' +# alias cat='bat' alias ls='eza' alias tree='eza --tree' alias c='clear' diff --git a/hosts/laptop-nixos/configuration.nix b/hosts/laptop-nixos/configuration.nix index 4a80055..949f643 100644 --- a/hosts/laptop-nixos/configuration.nix +++ b/hosts/laptop-nixos/configuration.nix @@ -109,6 +109,29 @@ # Services services.openssh.enable = true; + # battery levels notifier + systemd.timers."battery-notifier" = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnBootSec = "1m"; + OnUnitActiveSec = "1m"; + Unit = "battery-notifier.service"; + }; + }; + + systemd.services."battery-notifier" = { + script = '' + set -eu + export DISPLAY=:0.0 + touch $HOME/Desktop/EEEEEEE + $HOME/scripts/battery_notifier.sh + ''; + serviceConfig = { + Type = "oneshot"; + User = "kyren"; + }; + }; + # Open ports in the firewall. # networking.firewall.allowedTCPPorts = [ ... ]; # networking.firewall.allowedUDPPorts = [ ... ]; diff --git a/hosts/laptop-nixos/home.nix b/hosts/laptop-nixos/home.nix index f89e297..7b31b5a 100644 --- a/hosts/laptop-nixos/home.nix +++ b/hosts/laptop-nixos/home.nix @@ -48,6 +48,9 @@ python3Full watchexec golangci-lint + kdePackages.kdialog + xclip + libnotify ]; # Home Manager is pretty good at managing dotfiles. The primary way to manage diff --git a/scripts/battery_notifier.sh b/scripts/battery_notifier.sh new file mode 100755 index 0000000..17e77f8 --- /dev/null +++ b/scripts/battery_notifier.sh @@ -0,0 +1,23 @@ +set -eu +export DISPLAY=:0.0 +export XAUTHORIRTY=/home/kyren/.Xauthority + + +echo "$DISPLAY, $XAUTHORIRTY" >> "$HOME/Desktop/debug.log" + +battery_level=$(cat /sys/class/power_supply/BAT0/capacity) +battery_status=$(cat /sys/class/power_supply/BAT0/status) +echo "$battery_level% $battery_status" >> "$HOME/Desktop/debug.log" + +/etc/profiles/per-user/kyren/bin/notify-send --urgency=normal \ + --app-name="Battery Notifier" \ + --expire-time=5000 \ + "Battery at $battery_level%, unplug!" >> "$HOME/Desktop/debug.log" 2>&1 + +if [ "$battery_status" = "Charging" ] && [ "$battery_level" -ge 80 ]; then + touch "$HOME/Desktop/WHY" + /etc/profiles/per-user/kyren/bin/notify-send --urgency=normal \ + --app-name="Battery Notifier" \ + --expire-time=5000 \ + "Battery at $battery_level%, unplug!" >> "$HOME/Desktop/debug.log" 2>&1 +fi |
