Skip to content

Instantly share code, notes, and snippets.

@tbielawa
Created November 9, 2016 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbielawa/5b8ee263876baa1856aa34366c6dba44 to your computer and use it in GitHub Desktop.
Save tbielawa/5b8ee263876baa1856aa34366c6dba44 to your computer and use it in GitHub Desktop.
Dual battery status in screen hardline
# This set's a shell command with the ID #1,
# results expire every 15 seconds,
# and new results are fetched 1 second after expiration.
backtick 1 15 1 battery.sh
# I do this because I know it works
hardstatus alwayslastline
# Here's my current hardline:
hardstatus string "%{= rk} %{W}%H %{k}[ %{=kw}%-Lw%{r}(%{W}%n*%f%t%{r})%{k}%+Lw%= %{k}]%{-b W} [%{k r}%1`] %0C:%s %{g}"
# The key part of that hardline is where we format and display the result from the 'backtick' command (earlier)
# [%{k r}%1`]
# White text (k), red background (r), output from backtick id (#1)
# Example display:
# deepfryer [ (0*z) ] [⚡] 12:54:17
# ^- battery is charging
# deepfryer [ (0*z) ] [90.0/100.0%] 12:54:59
# ^ ^---------------- Built-in battery charge
# +--------------------- Pluggable battery charge
# IMPORTANT PART:
# [%{k r}%1`]
#!/bin/bash
CHARGING='⚡'
# Pluggable battery
CHARGE_NOW1=`cat /sys/class/power_supply/BAT1/energy_now`
CHARGE_MAX1=`cat /sys/class/power_supply/BAT1/energy_full`
STATUS1=`cat /sys/class/power_supply/BAT1/status`
# Built-in battery
CHARGE_NOW0=`cat /sys/class/power_supply/BAT0/energy_now`
CHARGE_MAX0=`cat /sys/class/power_supply/BAT0/energy_full`
STATUS0=`cat /sys/class/power_supply/BAT0/status`
CHARGE_NOW_SUM=$(( ${CHARGE_NOW1} + ${CHARGE_NOW0} ))
CHARGE_MAX_SUM=$(( ${CHARGE_MAX1} + ${CHARGE_MAX0} ))
# These commented out ones are just for debugging!!!
# echo -n "Pluggable battery % remaining: "
# echo "scale=1; (${CHARGE_NOW1}/${CHARGE_MAX1}) * 100" | bc
# echo -n "Built-in battery % remaining: "
# echo "scale=1; (${CHARGE_NOW0}/${CHARGE_MAX0}) * 100" | bc
# echo -n "Pluggable+Built-in battery % remaining: "
# echo "scale=1; (${CHARGE_NOW_SUM}/${CHARGE_MAX_SUM}) * 100" | bc
# Print the text which will appear in the hardline backtick
if [ "${STATUS1}" = "Charging" ]; then
echo -n ${CHARGING}
else
CHARGE1=`echo "scale=1; (${CHARGE_NOW1}/${CHARGE_MAX1}) * 100" | bc`
CHARGE0=`echo "scale=1; (${CHARGE_NOW0}/${CHARGE_MAX0}) * 100" | bc`
echo -n "${CHARGE1}/${CHARGE0}%"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment