config/modules/home/apps/helpers/waybar/mullvad-status.sh
2025-05-09 18:43:27 -04:00

35 lines
1,005 B
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
# Get status (fall back to “Disconnected” on error)
STATUS=$(mullvad status 2>/dev/null || echo "Disconnected")
if echo "$STATUS" | grep -q "^Connected"; then
# Extract relay hostname
SERVER=$(echo "$STATUS" |
sed -n 's/^[[:space:]]*Relay:[[:space:]]*//p' |
sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
# Grab the entire Visible location line (location + IPs)
FULL_LOC=$(echo "$STATUS" |
sed -n 's/^[[:space:]]*Visible location:[[:space:]]*//p')
# Split off the humanreadable location (before first dot)
LOCATION=${FULL_LOC%%.*}
# The part after the first “. ” is the IP info
IPS=${FULL_LOC#*. }
TOOLTIP="Connected via ${SERVER} (${IPS})"
# Emit JSON for Waybar
echo '{"text": "'"${LOCATION}"'"
, "tooltip": "'"${TOOLTIP}"'"
, "class": "connected"
}'
else
echo '{"text": "Disconnected"
, "tooltip": "Mullvad: Disconnected"
, "class": "disconnected"
}'
fi