mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-05-12 18:28:36 +00:00
Compare commits
No commits in common. "b93efba0fd22721be663e51c7c7d49cbc0d7a892" and "6c5c3fb36c3ad6858300d2291427e370b97f24b9" have entirely different histories.
b93efba0fd
...
6c5c3fb36c
5 changed files with 1 additions and 108 deletions
|
@ -1,13 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description="Show a notification when the battery is low"
|
|
||||||
PartOf=graphical-session.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ExecStart=%h/.local/bin/scripts/gui/battery-notification
|
|
||||||
Type=oneshot
|
|
||||||
RemainAfterExit=false
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=3s
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=wm-ready.target
|
|
|
@ -1,9 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description="Timer for low battery notification sendout"
|
|
||||||
PartOf=graphical-session.target
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
OnUnitActiveSec=20s
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=wm-ready.target
|
|
|
@ -1 +0,0 @@
|
||||||
/home/itsdrike/.config/systemd/user/battery-notification.timer
|
|
|
@ -1,83 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# This is a script which can be kept running as a cronjob or systemd timer to
|
|
||||||
# notify the user when the battery is low.
|
|
||||||
|
|
||||||
# $BATTERY env var can be set manually, being the path of the device
|
|
||||||
# (in /sys/class/power_supply/) i.e. BATTERY=/sys/class/power_supply/BAT0.
|
|
||||||
#
|
|
||||||
# If left unset, the script will automatically pick the battery device
|
|
||||||
# with the most recent change time. (This provides some limited support
|
|
||||||
# for systems with multiple batteries.)
|
|
||||||
#
|
|
||||||
# If the battery reaches below $NOTIFY_THRESHOLD (defaults to 5%),
|
|
||||||
# a notification will be shown. Note that only a single notification
|
|
||||||
# will be shown per charge cycle.
|
|
||||||
|
|
||||||
NOTIFY_THRESHOLD="${NOTIFY_THRESHOLD:-5}"
|
|
||||||
|
|
||||||
if [ -z "${BATTERY:-}" ]; then
|
|
||||||
BATTERY="$(find /sys/class/power_supply -maxdepth 1 -name 'BAT*' -exec stat -c '%Y %n' {} + | sort -k1,1nr | head -n 1 | cut -d' ' -f2-)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
NOTIFY_LOCK_FILE=/tmp/battery-notif
|
|
||||||
|
|
||||||
get_bat_info() {
|
|
||||||
cat "$BATTERY"/"$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
capacity="$(get_bat_info capacity)"
|
|
||||||
status="$(get_bat_info status)"
|
|
||||||
|
|
||||||
reset_notify() {
|
|
||||||
if [ -f "$NOTIFY_LOCK_FILE" ]; then
|
|
||||||
echo "Resetting notification flag"
|
|
||||||
rm -f "$NOTIFY_LOCK_FILE"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
maybe_notify() {
|
|
||||||
if [ -f "$NOTIFY_LOCK_FILE" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Sending notification"
|
|
||||||
notify-send \
|
|
||||||
-a battery-notification \
|
|
||||||
-u critical \
|
|
||||||
-i "$(pick_battery_icon)" \
|
|
||||||
"Battery low" "Battery is below $NOTIFY_THRESHOLD%"
|
|
||||||
touch "$NOTIFY_LOCK_FILE"
|
|
||||||
}
|
|
||||||
|
|
||||||
pick_battery_icon() {
|
|
||||||
local icon_candidate
|
|
||||||
local data_dirs="${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" # fallback
|
|
||||||
local IFS=':'
|
|
||||||
|
|
||||||
for icon_candidate in battery-caution battery-low battery; do
|
|
||||||
for dir in $data_dirs; do
|
|
||||||
if find "$dir/icons" -type f -iname "${icon_candidate}.*" 2>/dev/null | grep -q .; then
|
|
||||||
echo "$icon_candidate"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# The battery is not discharging (i.e. charging or full),
|
|
||||||
# we don't need to notify the user.
|
|
||||||
if [ "$status" != "Discharging" ]; then
|
|
||||||
reset_notify
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$capacity" -gt "$NOTIFY_THRESHOLD" ]; then
|
|
||||||
reset_notify
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
maybe_notify
|
|
|
@ -103,8 +103,7 @@ paru -S --noconfirm --needed \
|
||||||
|
|
||||||
# Utilities
|
# Utilities
|
||||||
paru -S --noconfirm --needed \
|
paru -S --noconfirm --needed \
|
||||||
nm-connection-editor ffmpegthumbnailer upower devour hyfetch fastfetch bottom tesseract tesseract-data-eng \
|
nm-connection-editor ffmpegthumbnailer upower devour hyfetch fastfetch bottom tesseract tesseract-data-eng
|
||||||
nvtop
|
|
||||||
|
|
||||||
# Wayland Utilities
|
# Wayland Utilities
|
||||||
paru -S --noconfirm --needed \
|
paru -S --noconfirm --needed \
|
||||||
|
|
Loading…
Add table
Reference in a new issue