Code and documentation cleanup.

This commit is contained in:
Storm Dragon committed 2026-05-16 19:23:30 -04:00
1 parent 9859cc348b
commit 1b95555007
13 files changed
+165 -116

No files matched your search

+12 -9
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# This file is part of I38.
@@ -23,7 +23,9 @@ if [[ "$batteryName" == "" ]]; then
fi
# If there's no file, we don't check it.
if [[ ! -f "/sys/class/power_supply/${batteryName}/capacity" ]]; then
batteryCapacityPath="/sys/class/power_supply/${batteryName}/capacity"
batteryStatusPath="/sys/class/power_supply/${batteryName}/status"
if [[ ! -f "$batteryCapacityPath" ]]; then
spd-say -P important -Cw "Battery not found."
exit 0
fi
@@ -31,8 +33,8 @@ fi
oldPercent="$(tail -1 "$0" | tr -cd '[:digit:]')"
oldPercent="${oldPercent:-0}"
percent=$(cat "/sys/class/power_supply/${batteryName}/capacity" | tr -cd '[:digit:]')
status="$(cat "/sys/class/power_supply/${batteryName}/status")"
percent=$(tr -cd '[:digit:]' < "$batteryCapacityPath")
status="$(cat "$batteryStatusPath")"
# If status is requested, give it and exit.
if [[ "$1" == "-s" || "$1" == "--status" ]]; then
@@ -41,24 +43,25 @@ if [[ "$1" == "-s" || "$1" == "--status" ]]; then
fi
if [[ $percent -ne $oldPercent && $percent -gt 10 ]]; then
spd-say "Battery $(</sys/class/power_supply/${batteryName}/capacity) percent."
spd-say "Battery $(<"$batteryCapacityPath") percent."
fi
if [[ $percent -le 10 ]]; then
spd-say "Battery $(</sys/class/power_supply/${batteryName}/capacity) percent."
spd-say "Battery $(<"$batteryCapacityPath") percent."
fi
if [[ "$status" == "Full" ]]; then
spd-say "Battery $(</sys/class/power_supply/${batteryName}/capacity) percent, ${status,,}."
spd-say "Battery $(<"$batteryCapacityPath") percent, ${status,,}."
fi
# remove the last line of the file and update it with the new percentage.
lastLine="$(grep -n '^exit 0' $0)"
lastLine="$(grep -n '^exit 0' "$0")"
# Convert lastLine to a number andd increment it by 1.
lastLine=${lastLine%%:*}
lastLine=$((lastLine + 1))
sed -i "${lastLine}"',$d' $0
sed -i "${lastLine}"',$d' "$0"
echo "$percent" >> "$0"
exit 0
# shellcheck disable=SC2317
50