summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfilip <“filip.rabiega@gmail.com”>2026-01-21 18:01:02 +0100
committerfilip <“filip.rabiega@gmail.com”>2026-01-21 18:01:02 +0100
commitd127601c83c1a30063b76eb89bf0d9a32ed435b9 (patch)
tree939d45697205ecd2f2b7bd972bb9e2787fa5af2f
parent704e1b7c0980fd83e07e6ab9d850c7558306250c (diff)
downloadchadscripts-d127601c83c1a30063b76eb89bf0d9a32ed435b9.tar.gz
chadscripts-d127601c83c1a30063b76eb89bf0d9a32ed435b9.tar.bz2
chadscripts-d127601c83c1a30063b76eb89bf0d9a32ed435b9.zip
rewrite sysact and batterylow
-rwxr-xr-xbatterylow19
-rwxr-xr-xsysact16
2 files changed, 21 insertions, 14 deletions
diff --git a/batterylow b/batterylow
index 2086cb2..0f2ebd4 100755
--- a/batterylow
+++ b/batterylow
@@ -1,15 +1,22 @@
#!/bin/sh
-# This script sends notifications when battery is low.
+# This script sends notifications when battery is low,
+# but only while discharging.
-# those variables may be unnecessary
-export DISPLAY=:0
-export HOME=/home/filipek
+battery=$(upower -e | grep BAT | head -n 1)
-percentage=$(upower -i "$(upower -e | grep BAT)" |
+percentage=$(upower -i "$battery" |
awk '/percentage/ {gsub(/%/, "", $2); print $2}')
+state=$(upower -i "$battery" |
+ awk '/state/ {print $2}')
+
+# Only notify if the battery is discharging
+if [ "$state" != "discharging" ]; then
+ exit 0
+fi
+
if [ "$percentage" -le 5 ]; then
notify-send "Battery very low."
-elif [ "$percentage" -ge 14 ] && [ "$percentage" -le 15 ]; then
+elif [ "$percentage" -le 15 ]; then
notify-send "Battery low."
fi
diff --git a/sysact b/sysact
index f1ac203..57672f4 100755
--- a/sysact
+++ b/sysact
@@ -25,12 +25,12 @@ lock(){
case "$(printf "🔒 lock\n🚪 leave $WM\n♻️ renew $WM\n🐻 hibernate\n🔃 reboot\n🖥️shutdown\n💤 sleep\n📺 display off" | dmenu -i -p 'Action: ')" in
'🔒 lock') lock ;;
-"🚪 leave $WM") kill -TERM "$(wmpid)" ;;
-"♻️ renew $WM") kill -HUP "$(wmpid)" ;;
-'🐻 hibernate') slock $ctl hibernate -i ;;
-'💤 sleep') slock $ctl suspend -i ;;
-'🔃 reboot') $ctl reboot -i ;;
-'🖥️shutdown') $ctl poweroff -i ;;
-'📺 display off') xset dpms force off ;;
-*) exit 1 ;;
+ "🚪 leave $WM") kill -TERM "$(wmpid)" ;;
+ "♻️ renew $WM") kill -HUP "$(wmpid)" ;;
+ '🐻 hibernate') slock $ctl hibernate -i ;;
+ '💤 sleep') slock $ctl suspend -i ;;
+ '🔃 reboot') $ctl reboot -i ;;
+ '🖥️shutdown') $ctl poweroff -i ;;
+ '📺 display off') xset dpms force off ;;
+ *) exit 1 ;;
esac