From 5fb19f10389b70ee2389755106092a9ef6c64598 Mon Sep 17 00:00:00 2001 From: David Moc Date: Sun, 24 May 2026 11:48:07 +0200 Subject: Go --- polybar/scripts/wg-pc-status.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 polybar/scripts/wg-pc-status.sh (limited to 'polybar/scripts/wg-pc-status.sh') diff --git a/polybar/scripts/wg-pc-status.sh b/polybar/scripts/wg-pc-status.sh new file mode 100755 index 0000000..b708695 --- /dev/null +++ b/polybar/scripts/wg-pc-status.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +iface="${WG_QUICK_PROFILE:-PC}" + +age_label() { + local latest now age + + latest="$(wg show "$iface" latest-handshakes 2>/dev/null | awk 'NF { if ($2 > newest) newest = $2 } END { print newest + 0 }')" + if [ -z "$latest" ] || [ "$latest" -le 0 ] 2>/dev/null; then + return 0 + fi + + now="$(date +%s)" + age=$((now - latest)) + + if [ "$age" -lt 60 ]; then + printf ' %ss' "$age" + elif [ "$age" -lt 3600 ]; then + printf ' %sm' "$((age / 60))" + elif [ "$age" -lt 86400 ]; then + printf ' %sh' "$((age / 3600))" + else + printf ' %sd' "$((age / 86400))" + fi +} + +if [ -d "/sys/class/net/$iface" ]; then + echo "%{F#98971a}up$(age_label)%{F-}" +else + echo "%{F#cc241d}down%{F-}" +fi -- cgit v1.2.3