From e0644451a0e7c1ad5eb6fb1905837ba2a3ea91cb Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 21 Aug 2021 20:31:59 -0400 Subject: Move panel applet scripts to lib/panel/ --- (limited to 'lib/panel/batmon') diff --git a/lib/panel/batmon b/lib/panel/batmon new file mode 100755 index 0000000..fec22b7 --- /dev/null +++ b/lib/panel/batmon @@ -0,0 +1,44 @@ +#!/bin/sh + +bat() +{ + eval "$(cat /sys/class/power_supply/BAT0/uevent | grep -E \ + '^POWER_SUPPLY_(STATUS|ENERGY_)')" + percentage=$(printf 'scale = 0; %d * 100 / %d;\n' \ + ${POWER_SUPPLY_ENERGY_NOW} ${POWER_SUPPLY_ENERGY_FULL} | bc) + case "${POWER_SUPPLY_STATUS}" in + 'Unknown') + status='?' + ;; + 'Charging') + status='⚡' + ;; + 'Discharging') + status='🔋' + ;; + 'Not charging') + status='!' + ;; + 'Full') + status='🔌' + ;; + esac + printf '%s%3d%%\n' "${status}" ${percentage} +} + +ac() +{ + status='🔌' + printf '%s\n' "${status}" +} + +main() +{ + if [ -e /sys/class/power_supply/BAT0/uevent ]; then + bat + else + ac + fi +} + +main "${@}" -- cgit v0.9.1