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 03f6da6f20c71461e0156feb0bd3d912ff58e8e3
parent 925b2a4f6be20a7d09867067b67206e3a56f5ead
Author: mcol <mcol@posteo.net>
Date:   Sat, 16 Feb 2019 00:55:52 +0000

added run module, cleaned up some others

Diffstat:
Mmodules/cpu | 16+++++++++++-----
Mmodules/headphones | 2+-
Amodules/run | 21+++++++++++++++++++++
Mmodules/wireguard | 19+++++++++++++++----
4 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/modules/cpu b/modules/cpu @@ -9,6 +9,7 @@ # bars # $cpu_bg : background colour for module # $cpu_fg : foreground colour for module +# $cpu_refresh : number of seconds to wait between refreshing value _cpu() { @@ -16,21 +17,26 @@ _cpu() { local output local cpu_val local prev_cpu_val + local cpu_args [[ -z "$cpu_bg" ]] && cpu_bg=$background [[ -z "$cpu_fg" ]] && cpu_fg=$foreground if ${cpu_bars:-true} then - cpu_bars=-b - else - cpu_bars= + cpu_args=-b fi - $dir/src/cpu $cpu_bars | while read cpu_val + if [[ -n "$cpu_refresh" ]] + then + cpu_args="$cpu_args -t $cpu_refresh" + fi + + $dir/src/cpu $cpu_args | while read cpu_val do [[ $cpu_val = $prev_cpu_val ]] && continue - output=${pad}${cpu_val}${pad} + [[ $cpu_val -lt 10 ]] && cpu_val=" $cpu_val" + output=${pad}${cpu_prefix}${cpu_val}${cpu_suffix}${pad} output=%{F$cpu_fg}%{B$cpu_bg}${output}%{B-}%{F-} output=${cpu_pre}${output}${cpu_post} echo "cpu='$output'" diff --git a/modules/headphones b/modules/headphones @@ -29,7 +29,7 @@ update_headphones() { _headphones() { [[ -z "$headphones_in" ]] && - headphones_in='%{B$highlight}${pad}${pad}%{B-}' + headphones_in='%{B$highlight}${pad}${pad}%{B-}' [[ -z "$headphones_out" ]] && headphones_out= diff --git a/modules/run b/modules/run @@ -0,0 +1,21 @@ +#---------------------------------------------------------------------------------- +# run program module +#---------------------------------------------------------------------------------- + +# This just displays unchanging text and will run a specified command +# +# Settings: +# $run_format : format string. Default '${pad}${pad}' + +_run() { + get_clicks run + + [[ -z "$run_format" ]] && \ + run_format='${pad}${pad}' + + eval run_format=$run_format + run_format=${run_pre}${run_format}${run_post} + echo "run='$run_format'" > $fifo 2>> $log & +} + +# vim: ft=sh diff --git a/modules/wireguard b/modules/wireguard @@ -4,7 +4,8 @@ # This shows presence of a wireguard interface -# It polls every 15 seconds for the interface in /sys/class/net +# It polls every 10 seconds for the interface in /sys/class/net +# It only updates lemonbar if the status has changed # Settings: # $wireguard_interface : interface to check for (default wg0) @@ -16,6 +17,8 @@ _wireguard() { [ -n "$wireguard_interface" ] || wireguard_interface=wg0 get_clicks wireguard + local wg_is_up=false + [[ -z "$wireguard_up_format" ]] && wireguard_up_format='%{B$highlight}${pad}${pad}%{B-}' [[ -z "$wireguard_down_format" ]] && @@ -24,11 +27,19 @@ _wireguard() { while true; do if [[ -e /sys/class/net/$wireguard_interface ]] then - echo "wireguard='${wireguard_pre}$(eval echo $wireguard_up_format)${wireguard_post}'" + if ! $wg_is_up + then + wg_is_up=true + echo "wireguard='${wireguard_pre}$(eval echo $wireguard_up_format)${wireguard_post}'" + fi else - echo "wireguard='${wireguard_pre}$(eval echo $wireguard_down_format)${wireguard_post}'" + if $wg_is_up + then + wg_is_up=false + echo "wireguard='${wireguard_pre}$(eval echo $wireguard_down_format)${wireguard_post}'" + fi fi - sleep 15 + sleep 10 done > $fifo 2>> $log & }