Skip to content

Commit

Permalink
Merge pull request #300 from Theoreticallyhugo/bug/no-wifi-icon-on-linux
Browse files Browse the repository at this point in the history
Bug/no wifi icon on linux
  • Loading branch information
ethancedwards8 authored Oct 10, 2024
2 parents 75ba88e + 1325b49 commit 6e3e5bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
11 changes: 6 additions & 5 deletions scripts/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source $current_dir/utils.sh

# set your own hosts so that a wifi is recognised even without internet access
HOSTS=$(get_tmux_option "@dracula-network-hosts" "google.com github.com example.com")
wifi_label=$(get_tmux_option "@dracula-network-wifi-label" "")
ethernet_label=$(get_tmux_option "@dracula-network-ethernet-label" "Ethernet")

get_ssid()
{
Expand All @@ -15,18 +17,17 @@ get_ssid()
Linux)
SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p')
if [ -n "$SSID" ]; then
printf '%s' "$wifi_label$SSID"
echo "$wifi_label$SSID"
else
echo "$(get_tmux_option "@dracula-network-ethernet-label" "Ethernet")"
echo "$ethernet_label"
fi
;;

Darwin)
if networksetup -getairportnetwork en0 | cut -d ':' -f 2 | sed 's/^[[:blank:]]*//g' &> /dev/null; then
wifi_label=$(get_tmux_option "@dracula-network-wifi-label" "")
echo "$wifi_label$(networksetup -getairportnetwork en0 | cut -d ':' -f 2)" | sed 's/^[[:blank:]]*//g'
else
echo "$(get_tmux_option "@dracula-network-ethernet-label" "Ethernet")"
echo "$ethernet_label"
fi
;;

Expand All @@ -44,7 +45,7 @@ main()
{
network="$(get_tmux_option "@dracula-network-offline-label" "Offline")"
for host in $HOSTS; do
if ping -q -c 1 -W 1 $host &>/dev/null; then
if ping -q -c 1 -W 1 "$host" &>/dev/null; then
network="$(get_ssid)"
break
fi
Expand Down
20 changes: 10 additions & 10 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/usr/bin/env bash

get_tmux_option() {
local option=$1
local default_value=$2
local option_value=$(tmux show-option -gqv "$option")
local option="$1"
local default_value="$2"
local option_value="$(tmux show-option -gqv "$option")"
if [ -z "$option_value" ]; then
echo $default_value
echo "$default_value"
else
echo $option_value
echo "$option_value"
fi
}

get_tmux_window_option() {
local option=$1
local default_value=$2
local option_value=$(tmux show-window-options -v "$option")
local option="$1"
local default_value="$2"
local option_value="$(tmux show-window-options -v "$option")"
if [ -z "$option_value" ]; then
echo $default_value
echo "$default_value"
else
echo $option_value
echo "$option_value"
fi
}

Expand Down

0 comments on commit 6e3e5bf

Please sign in to comment.