summaryrefslogtreecommitdiff
path: root/desktop/spectrwm/examples/battery_status.sh
diff options
context:
space:
mode:
authorLEVAI Daniel <leva@ecentrum.hu>2013-04-24 07:14:11 -0400
committerNiels Horn <niels.horn@slackbuilds.org>2013-04-28 12:30:03 -0300
commitdec4a7c0b052fe9181aa00af7f0ff5fa381128ec (patch)
tree7108c662fa198330834e2b10955147c3943fe79f /desktop/spectrwm/examples/battery_status.sh
parent16da631ccdfcd828c83ffeabe7eb57fd4604caf8 (diff)
downloadslackbuilds-dec4a7c0b052fe9181aa00af7f0ff5fa381128ec.tar.gz
desktop/spectrwm: Updated for version 2.2.0.
Signed-off-by: dsomero <xgizzmo@slackbuilds.org>
Diffstat (limited to 'desktop/spectrwm/examples/battery_status.sh')
-rw-r--r--desktop/spectrwm/examples/battery_status.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/desktop/spectrwm/examples/battery_status.sh b/desktop/spectrwm/examples/battery_status.sh
new file mode 100644
index 0000000000..2e0cc101a4
--- /dev/null
+++ b/desktop/spectrwm/examples/battery_status.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+
+PREF=/sys/class/power_supply/BAT0
+[ -r "${PREF}" ] || exit 1
+
+
+BATTERY_STATUS=$(< ${PREF}/status)
+
+typeset -i FULL_CAPACITY=$(< ${PREF}/charge_full)
+typeset -i WARNING_CAPACITY=$(( ${FULL_CAPACITY} * 20 / 100 ))
+typeset -i LOW_CAPACITY=$(( ${FULL_CAPACITY} * 10 / 100 ))
+typeset -i REMAINING_CAPACITY=$(< ${PREF}/charge_now)
+
+REMAINING_PERCENTAGE=$( echo "scale=1; ${REMAINING_CAPACITY} * 100 / ${FULL_CAPACITY}" |bc )
+
+
+case "${BATTERY_STATUS}" in
+ 'Full') # battery full
+ printf "AC"
+ ;;
+ 'Discharging') # battery discharging
+ printf "${REMAINING_PERCENTAGE}%%"
+ ;;
+ 'Charging') # battery charging
+ printf "AC^${REMAINING_PERCENTAGE}%%"
+ ;;
+esac
+
+exit 0