aboutsummaryrefslogtreecommitdiff
path: root/x/battery
diff options
context:
space:
mode:
authorBryson Steck <me@brysonsteck.xyz>2023-09-03 00:13:21 -0600
committerBryson Steck <me@brysonsteck.xyz>2023-09-03 00:13:21 -0600
commit564505447e19354e596f303ab562fedca576589d (patch)
tree9af8e3d65c57c7ceb1e2ab75a8ab268763d154c3 /x/battery
parent3991ac66a5269986b066338c404daea026b4ecbb (diff)
downloaddotfiles-564505447e19354e596f303ab562fedca576589d.tar
dotfiles-564505447e19354e596f303ab562fedca576589d.tar.gz
dotfiles-564505447e19354e596f303ab562fedca576589d.tar.bz2
who knows lmao
Diffstat (limited to 'x/battery')
-rwxr-xr-xx/battery48
1 files changed, 48 insertions, 0 deletions
diff --git a/x/battery b/x/battery
new file mode 100755
index 0000000..10a3673
--- /dev/null
+++ b/x/battery
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+$| = 1;
+
+my $CRITICAL = undef;
+my $LOW = undef;
+my $CHARGING = undef;
+my $DEAD_LEVEL = 2;
+my $CRITICAL_LEVEL = 5;
+my $LOW_LEVEL = 10;
+
+while (1) {
+ my @acpi = split " ", `acpi | grep "Discharging" | grep -v "rate information"`;
+ my $battery_level = $acpi[3];
+ my $status = $acpi[2];
+ my $sent = undef;
+ $battery_level =~ s/%,//g;
+ $status =~ s/,//g;
+
+ if ($status =~ "Discharging") {
+ $CHARGING = undef;
+ if (!$CRITICAL) {
+ if (int($battery_level) <= int($CRITICAL_LEVEL)) {
+ $CRITICAL = 'def';
+ $sent = 'def';
+ system "notify-send -i \"battery-empty-symbolic\" -t 0 -u critical \"BATTERY CRITICAL\" \"Battery level is ${battery_level}%\n\nCharge the system NOW.\""
+ }
+ } if (!$LOW && !$sent) {
+ if (int($battery_level) <= int($LOW_LEVEL)) {
+ $LOW = 'def';
+ $sent = 'def';
+ system "notify-send -i \"battery-caution-symbolic\" -t 0 -u normal \"BATTERY LOW\" \"Battery level is ${battery_level}%\n\nCharge the system soon.\""
+ }
+ } if (int($battery_level) <= int($DEAD_LEVEL)) {
+ system "notify-send -t 0 -u critical \"SHUTTING DOWN\" \"Battery level is too low. The system will shutdown in 2 minutes to prevent corruption.\n\nCharge the system NOW to cancel the shutdown.\"";
+ system "doas shutdown -Ph 2 &";
+ }
+ } else {
+ if (!$CHARGING) {
+ $CHARGING = 'def';
+ $CRITICAL = undef;
+ $LOW = undef;
+ system "doas shutdown -c";
+ system "notify-send -t 3000 -i \"battery-good-charging-symbolic\" \"System is now charging\"";
+ }
+ }
+
+ sleep 30;
+}