Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions scripts/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ HOSTS=$(get_tmux_option "@dracula-network-hosts" "google.com github.com example.
wifi_label=$(get_tmux_option "@dracula-network-wifi-label" "")
ethernet_label=$(get_tmux_option "@dracula-network-ethernet-label" "Ethernet")

_get_wifi_ifname() {
if ! scutil <<< list |
awk -F/ '/Setup:.*AirPort$/{i=$(NF-1);exit} END {if(i) {print i} else {exit 1}}'; then
scutil <<< list | awk -F/ '/en[0-9]+\/AirPort$/ {print $(NF-1);exit}'
fi
}

get_ssid()
{
# Check OS
Expand All @@ -24,9 +31,21 @@ get_ssid()
;;

Darwin)
local wifi_network=$(ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}')
local airport=$(networksetup -getairportnetwork en0 | cut -d ':' -f 2 | head -n 1)
local ifname
local wifi_network
local airport

ifname=$(_get_wifi_ifname)

if (( $(echo "$(sw_vers -productVersion) > 25.0" | bc -l) )); then
wifi_network=$(networksetup -listpreferredwirelessnetworks "$ifname" | awk 'NR==2 && sub("\t","") { print; exit }')
else
wifi_network=$(ipconfig getsummary "$ifname" | awk -F ' SSID : ' '/ SSID : / {print $2}')
fi

airport=$(networksetup -getairportnetwork "$ifname" | cut -d ':' -f 2 | head -n 1)

airport=$(echo "$airport" | sed 's/^[[:blank:]]*//g')
if [[ $airport != "You are not associated with an AirPort network." ]]; then
echo "$wifi_label$airport" | sed 's/^[[:blank:]]*//g'
elif [[ $wifi_network != "" ]]; then
Expand Down