diff --git a/functions.d/ambient_get_ssid.fish b/functions.d/ambient_get_ssid.fish index bdc9684..f8a32f1 100644 --- a/functions.d/ambient_get_ssid.fish +++ b/functions.d/ambient_get_ssid.fish @@ -1,9 +1,18 @@ function ambient_get_ssid if not set -q ambient_ssid - if test (uname) = "Darwin" + if test (uname) = "Darwin" # On macOS, query the airport tool. set -g ambient_ssid (/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | sed -n 's/^ *SSID: //p') else - set -g ambient_ssid (iw dev | grep ssid | sed -n 's/^\s*ssid //p') + # Try to get the SSID via `iw`. This is the quickest, most widely supported option. + if command -q iw + set -g ambient_ssid (iw dev | grep ssid | sed -n 's/^\s*ssid //p' | string trim) + end + + # In some setups (why?), `iw dev` can't show an SSID. Try querying NetworkManager? + if test -z $ambient_ssid; and command -q nmcli + set -g ambient_ssid (nmcli -t -f type,name connection show --active |\ + string match -rg '802-11-wireless:(.*)') + end end end echo $ambient_ssid