#!/usr/bin/env bash # Fetch the active connection name and type # -t: Terse output # -f: Specific fields ACTIVE_CONN=$(nmcli -t -f NAME,TYPE connection show --active | grep -E '802-3-ethernet|802-11-wireless' | head -n 1) # If no connection is found, output nothing if [ -z "$ACTIVE_CONN" ]; then echo "" exit 0 fi # Extract the name and type using parameter expansion (faster than cut) CONN_NAME="${ACTIVE_CONN%%:*}" CONN_TYPE="${ACTIVE_CONN##*:}" # Output JSON for Waybar custom module if [[ "$CONN_TYPE" == *"802-11-wireless"* ]]; then # It's Wi-Fi echo "{\"text\": \"$CONN_NAME \", \"class\": \"wifi\"}" else # It's Ethernet echo "{\"text\": \"$CONN_NAME 󰊗\", \"class\": \"ethernet\"}" fi