Skip to content

Commit

Permalink
Merge pull request #282 from Theoreticallyhugo/feature/network-custom…
Browse files Browse the repository at this point in the history
…-labels

feature/custom labels and hosts
  • Loading branch information
ethancedwards8 authored Sep 5, 2024
2 parents ae99a70 + 786314e commit 84b6b00
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions scripts/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8

HOSTS="google.com github.com example.com"
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
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")

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

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

Expand All @@ -37,7 +42,7 @@ get_ssid()

main()
{
network="Offline"
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
network="$(get_ssid)"
Expand Down

0 comments on commit 84b6b00

Please sign in to comment.