tmux-kanagawa/scripts/network.sh
Peter Bui 62537a8c6b scripts/network.sh: use a list of hosts
- Use a list of hosts: google.com, github.com, example.com
- Script will try each in turn, stopping at the first one that connects
- Also fix she-bang and some quotes

- Tested with Wifi and Offline.
2020-04-29 09:36:11 -04:00

53 lines
1,018 B
Bash
Executable file

#!/usr/bin/env bash
#author: Dane Williams
#script for gathering internet connectivity info
#script is called in dracula.tmux program
HOSTS="google.com github.com example.com"
get_ssid()
{
# Check OS
case $(uname -s) in
Linux)
if iw dev | grep ssid | cut -d ' ' -f 2 &> /dev/null; then
echo "$(iw dev | grep ssid | cut -d ' ' -f 2)"
else
echo 'Ethernet'
fi
;;
Darwin)
if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 &> /dev/null; then
echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)"
else
echo 'Ethernet'
fi
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability
;;
*)
;;
esac
}
main()
{
network="Offline"
for host in $HOSTS; do
if ping -q -c 1 -W 1 $host &>/dev/null; then
network="$(get_ssid)"
break
fi
done
echo " $network"
}
#run main driver function
main