aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-08-19 12:42:52 +0200
committerCharles Cabergs <me@cacharle.xyz>2021-08-19 12:42:52 +0200
commit7d9345c9564370bdb32cbb06d24b238986572ea6 (patch)
treee9690847f8dca5dccfb759dd53b5b7895eb87872
parentf064922a74100af86def550d4ef6a50ab4e80203 (diff)
downloaddotfiles-7d9345c9564370bdb32cbb06d24b238986572ea6.tar.gz
dotfiles-7d9345c9564370bdb32cbb06d24b238986572ea6.tar.bz2
dotfiles-7d9345c9564370bdb32cbb06d24b238986572ea6.zip
Added battery-low-notify script and crontab to run it every 10min
-rw-r--r--crontab/laptop.crontab3
-rwxr-xr-xinstall11
-rwxr-xr-xlocal/bin/battery-low-check5
-rwxr-xr-xlocal/bin/battery-low-notify14
4 files changed, 26 insertions, 7 deletions
diff --git a/crontab/laptop.crontab b/crontab/laptop.crontab
new file mode 100644
index 0000000..18f36f1
--- /dev/null
+++ b/crontab/laptop.crontab
@@ -0,0 +1,3 @@
+*/10 * * * * . $HOME/.zprofile ; DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u $USER)/bus" DISPLAY=:0 battery-low-notify
+
+# vim:ft=crontab
diff --git a/install b/install
index 2c6ee73..892e845 100755
--- a/install
+++ b/install
@@ -6,7 +6,7 @@
if [ "$USER" = 'root' ]
then
- crontab 'crontab/root.crontab'
+ crontab crontab/root.crontab
exit
fi
@@ -96,7 +96,14 @@ parallel_wait
###############################################################################
echo '---------------------------- INSTALL CRONTAB -----------------------------'
-crontab 'crontab/user.crontab'
+
+if [ "$(hostname)" = 'charleslaptopcarbon' ]
+then
+ cat crontab/user.crontab crontab/laptop.crontab | crontab -
+else
+ crontab crontab/user.crontab
+fi
+
echo 'INFO: Run this script as root if you want to install the root contab'
###############################################################################
diff --git a/local/bin/battery-low-check b/local/bin/battery-low-check
deleted file mode 100755
index dbbdc6b..0000000
--- a/local/bin/battery-low-check
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-capacity=$(cat /sys/class/power_supply/BAT0/capacity)
-
-[ "$capacity" -lt 10 ] && notify-send -u critical "Battery low $capacity%"
diff --git a/local/bin/battery-low-notify b/local/bin/battery-low-notify
new file mode 100755
index 0000000..605ea91
--- /dev/null
+++ b/local/bin/battery-low-notify
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+battery_dir='/sys/class/power_supply/BAT0'
+
+[ ! -d "$battery_dir" ] && exit 1
+
+if [ "$(cat "$battery_dir/status")" != 'Charging' ]
+then
+ capacity="$(cat "$battery_dir/capacity")"
+ [ "$capacity" -lt 15 ] &&
+ notify-send -u critical "Battery low: $capacity%"
+fi
+
+exit 0