#!/usr/bin/env bash # WireGuard status using ip command (no wg show needed) ICON_ACTIVE="󰯄" # Shield with checkmark ICON_INACTIVE="󰒙" # Shield disabled # Get all WireGuard interfaces wg_interfaces=$(ip a | grep -o 'wg[0-9]\+' | sort -u) active_info="" tooltip="WireGuard Status" for interface in $wg_interfaces; do # Check if interface has an IP address ip_addr=$(ip -4 addr show dev "$interface" | grep -oP '(?<=inet\s)\d+(\.\d+){3}') if [ -n "$ip_addr" ]; then # Interface is active if [ -z "$active_info" ]; then active_info="%{F#a3be8c}$ICON_ACTIVE%{F-} $interface:$ip_addr" else active_info+=" $interface:$ip_addr" fi tooltip+="\n\n$interface" tooltip+="\nStatus: Active" tooltip+="\nIP: $ip_addr" else # Interface exists but inactive tooltip+="\n\n$interface" tooltip+="\nStatus: Inactive" fi done if [ -z "$wg_interfaces" ]; then # No WireGuard interfaces found echo "{\"text\":\"$ICON_INACTIVE\",\"tooltip\":\"No WireGuard interfaces configured\"}" elif [ -z "$active_info" ]; then # Interfaces exist but none active echo "{\"text\":\"$ICON_INACTIVE\",\"tooltip\":\"$tooltip\"}" else # Active interfaces found echo "{\"text\":\"$ICON_ACTIVE\",\"tooltip\":\"$tooltip\"}" fi