After macOS 15:
system_profiler SPAirPortDataType | awk '/Current Network Information:/ { getline; print substr($0, 13, (length($0) - 13)); exit }'
Found it here: https://snelson.us/2024/09/determining-a-macs-ssid-like-an-animal/