mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
feat: Adds battery monitor service, timer, and execution script.
This commit is contained in:
32
scripts/arch/battery-monitor
Executable file
32
scripts/arch/battery-monitor
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Used with the systemd battery monitor service and timer to alert
|
||||
# when the battery has dropped below the threshold and is not currently
|
||||
# charging.
|
||||
|
||||
THRESHOLD=20 # Notify when below 20%
|
||||
NOTIFICATION_FLAG="/run/user/${UID}/user_battery_notified"
|
||||
|
||||
function get-battery-percentage() {
|
||||
local battery=$(upower --battery | grep percentage)
|
||||
echo "${battery//[^0-9]/}"
|
||||
}
|
||||
|
||||
function send-battery-alert() {
|
||||
notify-send -u critical \
|
||||
"Recharge battery!" "Batttery is down to ${1}" \
|
||||
-i battery-caution \
|
||||
-t 30000
|
||||
}
|
||||
|
||||
battery_percentage=$(get-battery-percentage)
|
||||
battery_state=$(upower --battery | grep -E state | awk '{print $2}')
|
||||
|
||||
if [[ "$battery_state" == "discharging" && "$battery_percentage" -le "$THRESHOLD" ]]; then
|
||||
if [ ! -f "$NOTIFICATION_FLAG" ]; then
|
||||
send-battery-alert "$battery_percentage"
|
||||
touch "$NOTIFICATION_FLAG"
|
||||
fi
|
||||
else
|
||||
rm -f "$NOTIFICATION_FLAG"
|
||||
fi
|
||||
@@ -6,3 +6,4 @@ espanso service register
|
||||
sudo setcap "cap_dac_override+p" $(which espanso)
|
||||
|
||||
systemctl --user enable --now logout-task.service
|
||||
systemctl --user enable --now batter-monitor.timer
|
||||
|
||||
@@ -19,6 +19,7 @@ yay -S --noconfirm --needed \
|
||||
bc \
|
||||
btop \
|
||||
catppuccin-gtk-theme-mocha \
|
||||
sddm-theme-catppuccin \
|
||||
eza \
|
||||
fastfetch \
|
||||
fzf \
|
||||
@@ -34,6 +35,7 @@ yay -S --noconfirm --needed \
|
||||
nodejs \
|
||||
npm \
|
||||
nwg-look \
|
||||
pam-u2f \
|
||||
pcsc-tools \
|
||||
starship \
|
||||
swaync \
|
||||
|
||||
@@ -13,6 +13,7 @@ ln -sfv ~/.dotfiles/systemd ~/.config
|
||||
ln -sfv ~/.dotfiles/tree-sitter ~/.config
|
||||
ln -sfv ~/.dotfiles/walker ~/.config
|
||||
ln -sfv ~/.dotfiles/waybar ~/.config
|
||||
ln -sfv ~/.dotfiles/yubico ~/.config
|
||||
|
||||
# Espanso
|
||||
espanso service stop
|
||||
|
||||
Reference in New Issue
Block a user