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 811db9f8b7ab167beb4e514ed0425ed0952e74f5
parent f7cf0010b4649e34cfc683a019388d12e2e5f7f7
Author: mcol <mcol@posteo.net>
Date:   Sat,  2 Mar 2019 19:17:42 +0000

move main wireguard module into update_wireguard function for external calling

Diffstat:
Mmodules/wireguard | 33++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/modules/wireguard b/modules/wireguard @@ -13,32 +13,35 @@ # $wireguard_down_format : format. Default '%{B$urgent}${pad}${pad}%{B-}' +update_wireguard() { + if [[ -e /sys/class/net/$wireguard_interface ]] && ! $wg_is_up + then + wg_is_up=true + send "wireguard='${wireguard_pre}$(eval echo $wireguard_up_format)${wireguard_post}'" + + elif ! [[ -e /sys/class/net/$wireguard_interface ]] && $wg_is_up + then + wg_is_up=false + send "wireguard='${wireguard_pre}$(eval echo $wireguard_down_format)${wireguard_post}'" + fi +} + + _wireguard() { [ -n "$wireguard_interface" ] || wireguard_interface=wg0 get_clicks wireguard - local wg_is_up=false + local wg_is_up + wg_is_up=false [[ -z "$wireguard_up_format" ]] && wireguard_up_format='%{B$highlight}${pad}${pad}%{B-}' + [[ -z "$wireguard_down_format" ]] && wireguard_down_format='%{B$urgent}${pad}${pad}%{B-}' while true; do - if [[ -e /sys/class/net/$wireguard_interface ]] - then - if ! $wg_is_up - then - wg_is_up=true - send "wireguard='${wireguard_pre}$(eval echo $wireguard_up_format)${wireguard_post}'" - fi - else - if $wg_is_up - then - wg_is_up=false - send "wireguard='${wireguard_pre}$(eval echo $wireguard_down_format)${wireguard_post}'" - fi - fi + update_wireguard sleep 10 done & }