From 738d365231d081076abaee6a31fae989edf50d8d Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 7 Jan 2024 11:06:51 -0500 Subject: [PATCH] ADD kinda useless battery monitor script in case I want it later --- scripts/batmon | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 scripts/batmon diff --git a/scripts/batmon b/scripts/batmon new file mode 100755 index 0000000..8544cde --- /dev/null +++ b/scripts/batmon @@ -0,0 +1,22 @@ +#! /bin/bash + +# small script to log battery usage in txt file for conky to parse +# lovingly stolen from battery-stats by petter reinholdtsen + +DST_FILE="$XDG_CACHE_HOME/batmon.log" +SYS_BAT_PATH="/sys/class/power_supply/BAT0" +BAT_CAP_PATH="$SYS_BAT_PATH/charge_now" +BAT_CAP_FULL_PATH="$SYS_BAT_PATH/charge_full" +MAX_ENTRIES=1440 # number of minutes in day + +read_bat_percent() { + timestamp=$(date +%s) + charge_now=$(cat "$BAT_CAP_PATH") + charge_full=$(cat "$BAT_CAP_FULL_PATH") + percent=$(echo "100 * $charge_now / $charge_full" | bc) + echo $timestamp $percent >> "$DST_FILE" +} + +read_bat_percent +# truncate to most recent entries by max_entries +tail -n $MAX_ENTRIES "$DST_FILE" > /tmp/batmon.tmp.log && mv /tmp/batmon.tmp.log "$DST_FILE"