#!/bin/bash get_connected_wifi_device() { # Get the active Wi-Fi connections connections=$(nmcli -t -f DEVICE,TYPE,STATE device | grep -E '^.*:wifi:connected$' | cut -d: -f1) # Return the device name of the first connected Wi-Fi device, or an empty string if none are found if [ -z "$connections" ]; then echo "" else # Return the device name echo "$connections" | head -n 1 fi } get_connected_wifi_name() { # Get the device name of the first connected Wi-Fi device device=$(get_connected_wifi_device) # Return the SSID of the Wi-Fi device, or an empty string if none is found if [ -z "$device" ]; then echo "" else # Get the SSID (Wi-Fi name) for the connected device name=$(nmcli -t -f NAME,DEVICE connection show --active | grep -E "^.*:$device$" | cut -d: -f1) echo "$name" fi }