dotfiles/tmux/.tmux/scripts/tmux-vpn-status/vpn-status.sh
2025-12-28 12:26:00 -07:00

39 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
# VPN status for tmux statusline
# Check for VPN connection via multiple methods:
# 1. ProtonVPN GUI (uses NetworkManager with pvpn- prefix or WireGuard)
# 2. Old WireGuard config (protonvpn interface)
# 3. Any active VPN connection via NetworkManager
# Method 1: Check for ProtonVPN GUI WireGuard interface (pvpn-* or proton*)
if ip link 2>/dev/null | grep -qE "pvpn-|proton" | grep -qE "state UP"; then
echo "🛡️"
exit 0
fi
# Method 2: Check for any wireguard interface that's UP
if ip link 2>/dev/null | grep -E "wireguard|wg[0-9]+" | grep -qE "state UP"; then
echo "🛡️"
exit 0
fi
# Method 3: Check NetworkManager for active VPN connections
if nmcli -t -f TYPE,STATE connection show --active 2>/dev/null | grep -qE "vpn:activated|wireguard:activated"; then
echo "🛡️"
exit 0
fi
# Method 4: Check old protonvpn interface (legacy)
if ip link show protonvpn 2>/dev/null | grep -qE "<.*UP.*>"; then
echo "🛡️"
exit 0
fi
# Method 5: Check if default route goes through a VPN-like interface
if ip route show default 2>/dev/null | grep -qE "pvpn-|proton|wg[0-9]+|tun[0-9]+"; then
echo "🛡️"
exit 0
fi
# No VPN detected
echo "❌"