From 1570f06b6c95697830af2454016f41bedb5ed507 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Thu, 21 Nov 2024 23:24:10 +0100 Subject: [PATCH] Add VPN state to sway status bar --- linux_home/.config/sway/status.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/linux_home/.config/sway/status.sh b/linux_home/.config/sway/status.sh index 94a2dbe..52fc429 100755 --- a/linux_home/.config/sway/status.sh +++ b/linux_home/.config/sway/status.sh @@ -1,6 +1,23 @@ #!/bin/sh while true; do + # VPN (Mullvad) + vpn_status=$(mullvad status) + # Example output: + # ------------------------- +# Connected +# Relay: se-mma-wg-101 +# Features: Quantum Resistance +# Visible location: Sweden, Malmö. IPv4: 45.83.220.204 + # ------------------------- + is_connected=$(echo "$vpn_status" | grep -oP "Connected" | wc -l) + if [ $is_connected -eq 1 ]; then + visible_location=$(echo "$vpn_status" | grep -oP "Visible location:\s+\K.*" | cut -d. -f1) + vpn_status="VPN: $visible_location" + else + vpn_status="VPN: Disconnected" + fi + # Network status ssid=$(nmcli -t -f ACTIVE,SSID dev wifi | grep -E '^yes' | cut -d: -f2) if [ -z "$ssid" ]; then @@ -39,7 +56,7 @@ while true; do if [ -n "$bluetooth_status" ]; then final_status="$bluetooth_status | " fi - final_status="$final_status$brightness_status | $battery | $network_status | $date_time " + final_status="$final_status$brightness_status | $battery | $vpn_status | $network_status | $date_time " echo "$final_status" sleep 1