From 0e138f5409062c0bd28274d707f7d61945a30114 Mon Sep 17 00:00:00 2001 From: Daniel Carrillo Date: Sun, 29 Aug 2021 17:43:15 +0200 Subject: [PATCH] [polybar] Add network signal status --- .config/polybar/bar.ini | 2 +- .config/polybar/modules.ini | 6 +++++ .config/polybar/scripts/network_status | 35 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 .config/polybar/scripts/network_status diff --git a/.config/polybar/bar.ini b/.config/polybar/bar.ini index 198ad93..e85bf99 100644 --- a/.config/polybar/bar.ini +++ b/.config/polybar/bar.ini @@ -69,7 +69,7 @@ font-6 = "Font Awesome 5 Brands-Regular-400:size=32:antialias=true;1" modules-left = polywins modules-center = custom_date -modules-right = updates cpu_bar memory_bar docker vpn network_usage alsa_bar +modules-right = updates cpu_bar memory_bar docker vpn network_status network_usage alsa_bar cursor-click = pointer cursor-scroll = ns-resize diff --git a/.config/polybar/modules.ini b/.config/polybar/modules.ini index 9e4c478..ba84ffe 100644 --- a/.config/polybar/modules.ini +++ b/.config/polybar/modules.ini @@ -87,6 +87,12 @@ double-click-left = /usr/bin/bash ~/.config/polybar/scripts/nmcli_manager & click-right = /usr/bin/bash ~/.config/polybar/scripts/nmcli_manager & tail = true +[module/network_status] +type = custom/script +exec = ~/.config/polybar/scripts/network_status +click-left = $TERMINAL_CMD "fping --elapsed --count 100 1.1.1.1" +interval = 5 + [module/vpn] type = custom/script exec = ~/.config/polybar/scripts/check_vpn diff --git a/.config/polybar/scripts/network_status b/.config/polybar/scripts/network_status new file mode 100755 index 0000000..91c5b48 --- /dev/null +++ b/.config/polybar/scripts/network_status @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +URL=${1:-1.1.1.1} + +output=$(fping --quiet --outage --count=5 "$URL" 2>&1) +outage_output="" +outage_color="FFFFFF" +avg_output="" +avg_color="FFFFFF" + +avg=$(echo "$output" | cut -d "," -f 3 | cut -d "=" -f 2 | cut -d "/" -f 2 | cut -d "." -f 1) +outage=$(echo "$output" | cut -d "," -f 2 | cut -d "=" -f 2 | tr -d " " | cut -d "." -f 1) + +if [ "$outage" -eq 0 ] || [ -z "$outage" ]; then + outage_output="" +elif [ "$outage" -lt 30 ]; then + outage_color=F5A70A +else + outage_color=FF0000 +fi + +if [ -z "$avg" ] || [ "$avg" -gt 60 ]; then + avg_color=FF0000 +elif [ "$avg" -lt 40 ]; then + avg_output="" +else + avg_color=F5A70A +fi + +if [ -n "$outage_output" ] || [ -n "$avg_output" ]; then + echo "%{F#$outage_color}%{T5}${outage_output}%{F-}%{T-}%{F#$avg_color}%{T5} ${avg_output}%{F-}%{T-}" +else + echo "" +fi +