aboutsummaryrefslogtreecommitdiff
path: root/low-bat-notifier
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2025-09-24 05:01:20 +0200
committersrdusr <trevorgray@srdusr.com>2025-09-24 05:01:20 +0200
commit553cb2204b0bf27afe13c6332f5679bbd47172a0 (patch)
tree75c86ff018122a682e0afd7a0e2a0228a63e44bd /low-bat-notifier
parentb20e4e004be74884cc72c57a3128e36fd5177d7a (diff)
downloaddotfiles-553cb2204b0bf27afe13c6332f5679bbd47172a0.tar.gz
dotfiles-553cb2204b0bf27afe13c6332f5679bbd47172a0.zip
Update/Overhaul
Diffstat (limited to 'low-bat-notifier')
-rwxr-xr-xlow-bat-notifier66
1 files changed, 0 insertions, 66 deletions
diff --git a/low-bat-notifier b/low-bat-notifier
deleted file mode 100755
index be346f4..0000000
--- a/low-bat-notifier
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/bin/bash
-
-### VARIABLES
-
-POLL_INTERVAL=120 # seconds at which to check battery level
-LOW_BAT=33 # lesser than this is considered low battery
-
-# If BAT0 doesn't work for you, check available devices with command below
-#
-# $ ls -1 /sys/class/power_supply/
-#
-BAT_PATH=/sys/class/power_supply/BAT0
-BAT_STAT=$BAT_PATH/status
-
-if [[ -f $BAT_PATH/charge_full ]]
-then
- BAT_FULL=$BAT_PATH/charge_full
- BAT_NOW=$BAT_PATH/charge_now
-elif [[ -f $BAT_PATH/energy_full ]]
-then
- BAT_FULL=$BAT_PATH/energy_full
- BAT_NOW=$BAT_PATH/energy_now
-else
- exit
-fi
-
-### END OF VARIABLES
-
-kill_running() { # stop older instances to not get multiple notifications
- local mypid=$$
-
- declare pids=($(pgrep -f ${0##*/}))
-
- for pid in ${pids[@]/$mypid/}; do
- kill $pid
- sleep 1
- done
-}
-
-launched=0
-
-# Run only if battery is detected
-if ls -1qA /sys/class/power_supply/ | grep -q BAT
-then
-
- kill_running
-
- while true
- do
- bf=$(cat $BAT_FULL)
- bn=$(cat $BAT_NOW)
- bs=$(cat $BAT_STAT)
-
- bat_percent=$(( 100 * $bn / $bf ))
-
- if [[ $bat_percent -lt $LOW_BAT && "$bs" = "Discharging" && $launched -lt 3 ]]
- then
- notify-send --urgency=critical "$bat_percent% : Low Battery!"
- launched=$((launched+1))
- elif [[ "$bs" = "Charging" ]]
- then
- launched=0
- fi
- sleep $POLL_INTERVAL
- done
-fi