From 027fa3c088b32e64613134f1436b667e5366af30 Mon Sep 17 00:00:00 2001 From: embr Date: Wed, 26 Oct 2022 16:22:21 +0200 Subject: [PATCH] ambient_get_ssid: fall back to nmcli if iw has no ssid --- functions.d/ambient_get_ssid.fish | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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