Super hacky shell wrapper around lemonbar that aims to poll as little as possible, minimising bar updates to the screen and reduce resource usage.
git clone https://mcol.xyz/code/lemontools
Log | Files | Refs | README | LICENSE

commit f48275c93cfe2311b7c84e9664eb5724c3696aca
parent 2c9de65f832cae3153fa590591c3752b9454f8f6
Author: mcol <mcol@posteo.net>
Date:   Sat, 16 Feb 2019 00:54:00 +0000

more concise battery module. Also show font awesome 5 icon if wanted

Diffstat:
Mmodules/battery | 72+++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 53 insertions(+), 19 deletions(-)

diff --git a/modules/battery b/modules/battery @@ -8,30 +8,56 @@ # $battery_capacity : full path to battery capacity file # $battery_status : full path to charging status file -update_battery(){ + +if ${battery_icon:-false} +then + prepend_battery_icon() { + case "$((( $1 / 20 )))" in + 0) + echo " $1" + ;; + 1) + echo " $1" + ;; + 2) + echo " $1" + ;; + 3) + echo " $1" + ;; + 4|5) + echo " $1" + ;; + esac + } +fi + +update_battery() { capacity=$(cat $battery_capacity) charging_status=$(cat $battery_status) + ${battery_icon:-false} && capacity=$(prepend_battery_icon $capacity) + { - if [ "$charging_status" = "Charging" ] && [[ $capacity -ge 95 ]] + if [[ "$charging_status" = "Charging" ]] && [[ $capacity -ge 95 ]] then # overcharging echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'" - elif [[ $capacity -le 10 ]] && [ "$charging_status" = "Discharging" ] + elif [[ $capacity -le 10 ]] && [[ "$charging_status" = "Discharging" ]] then # need to plug in echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'" - elif [ "$charging_status" = "Charging" ] + elif [[ "$charging_status" = "Charging" ]] then # charging echo "battery='%{B$highlight}${pad}${capacity}%${pad}%{B-}'" else # discharging echo "battery='${pad}${capacity}%${pad}'" - fi - } > $fifo 2>> $log + fi + } > $fifo 2>> $log } @@ -45,26 +71,34 @@ _battery() { capacity=$(cat $battery_capacity) charging_status=$(cat $battery_status) - if [ "$charging_status" = "Charging" ] && [[ $capacity -ge 95 ]] + if ${battery_icon:-false} then - # overcharging - echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'" + battery_format=$(prepend_battery_icon $capacity) + else + battery_format=$capacity + fi - elif [[ $capacity -le 10 ]] && [ "$charging_status" = "Discharging" ] + if [[ "$charging_status" = "Charging" ]] then - # need to plug in - echo "battery='%{B$urgent}${pad}${capacity}%${pad}%{B-}'" + if [[ $capacity -ge 95 ]] + then + # overcharging + echo "battery='%{B$urgent}${pad}${battery_format}%${pad}%{B-}'" + else + echo "battery='%{B$highlight}${pad}${battery_format}%${pad}%{B-}'" + fi - elif [ "$charging_status" = "Charging" ] - then - # charging - echo "battery='%{B$highlight}${pad}${capacity}%${pad}%{B-}'" else - # discharging - echo "battery='${pad}${capacity}%${pad}'" + if [[ $capacity -le 10 ]] + then + # need to plug in + echo "battery='%{B$urgent}${pad}${battery_format}%${pad}%{B-}'" + else + echo "battery='${pad}${battery_format}%${pad}'" + fi fi sleep 60 - done > $fifo 2>> $log & + done > $fifo 2>> $log & }