Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/custom labels and hosts #282

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
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