dracula / tmux

🧛🏻‍♂️ Dark theme for tmux
https://draculatheme.com/tmux
MIT License
657 stars 308 forks source link

Bug: Error obtaining wireless information on desktop Macs #264

Open moussaclarke opened 5 months ago

moussaclarke commented 5 months ago

Describe the bug

On desktop Macs, e.g. a macMini, the network shows as "Error obtaining Wireless information"

To Reproduce

Steps to reproduce the behavior:

  1. On a desktop mac connected to WiFi, add the network plugin
  2. Open tmux
  3. Look at the status line

Expected behavior

Status line should show the network SSID

Screenshots

Screenshot 2024-05-12 at 10 38 45

System

moussaclarke commented 5 months ago

Possibly related: https://github.com/dracula/tmux/pull/259 https://github.com/dracula/tmux/issues/256

I think what's going on is that en1 is wifi on desktop macs, not en0, so probably need to check which interface is active before calling networksetup

e.g. active=$(ifconfig | awk '/en0/ && /inet/ {print "en0"} /en1/ && /inet/ {print "en1"}')

moussaclarke commented 5 months ago

This fixes it for me https://github.com/moussaclarke/dracula-tmux/commit/970eab249c55288a7a5b2b2804d2861c81a7b68f

Can submit as PR if appropriate.

oiavorskyi commented 5 months ago

This fix does not work in the scenario where wither wired or both wireless and wired connections are used. Command networksetup -getairportnetwork $interface | cut -d ':' -f 2 | sed 's/^[[:blank:]]*//g' responses with

en0 is not a Wi-Fi interface.
Error obtaining wireless information.
moussaclarke commented 5 months ago

Ok I guess we could fall back to Ethernet if we get that response from networksetup -getairportnetwork on the active interface.

Otherwise when I get a minute I'll see if I can figure out a less indirect way of checking the type of connection before calling networksetup -getairportnetwork - probably via ifconfig again

moussaclarke commented 5 months ago

@oiavorskyi updated: https://github.com/moussaclarke/dracula-tmux/commit/9770d3752584a1609045a6bf1f7af92f37cb16fb

I couldn't find a straightforward way to get the connection type, so just checking for the presence of the error message string. Feels somewhat brittle though? Also added a "No connection" status

Will test it on a wired connection when I get the chance.

oiavorskyi commented 5 months ago

@moussaclarke sorry for not responding in a very long time, I was on a vacation. Maybe it is possible to use the result of networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/{getline; print $2}' to check which interface(s) are WiFi ones and then see if it is used a an active interface?