Skip to content

Commit 84b6b00

Browse files
Merge pull request #282 from Theoreticallyhugo/feature/network-custom-labels
feature/custom labels and hosts
2 parents ae99a70 + 786314e commit 84b6b00

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/network.sh

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# setting the locale, some users have issues with different locales, this forces the correct one
33
export LC_ALL=en_US.UTF-8
44

5-
HOSTS="google.com github.com example.com"
5+
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
source $current_dir/utils.sh
7+
8+
# set your own hosts so that a wifi is recognised even without internet access
9+
HOSTS=$(get_tmux_option "@dracula-network-hosts" "google.com github.com example.com")
610

711
get_ssid()
812
{
@@ -11,17 +15,18 @@ get_ssid()
1115
Linux)
1216
SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p')
1317
if [ -n "$SSID" ]; then
14-
printf '%s' "$SSID"
18+
printf '%s' "$wifi_label$SSID"
1519
else
16-
echo 'Ethernet'
20+
echo "$(get_tmux_option "@dracula-network-ethernet-label" "Ethernet")"
1721
fi
1822
;;
1923

2024
Darwin)
2125
if networksetup -getairportnetwork en0 | cut -d ':' -f 2 | sed 's/^[[:blank:]]*//g' &> /dev/null; then
22-
echo "$(networksetup -getairportnetwork en0 | cut -d ':' -f 2)" | sed 's/^[[:blank:]]*//g'
26+
wifi_label=$(get_tmux_option "@dracula-network-wifi-label" "")
27+
echo "$wifi_label$(networksetup -getairportnetwork en0 | cut -d ':' -f 2)" | sed 's/^[[:blank:]]*//g'
2328
else
24-
echo 'Ethernet'
29+
echo "$(get_tmux_option "@dracula-network-ethernet-label" "Ethernet")"
2530
fi
2631
;;
2732

@@ -37,7 +42,7 @@ get_ssid()
3742

3843
main()
3944
{
40-
network="Offline"
45+
network="$(get_tmux_option "@dracula-network-offline-label" "Offline")"
4146
for host in $HOSTS; do
4247
if ping -q -c 1 -W 1 $host &>/dev/null; then
4348
network="$(get_ssid)"

0 commit comments

Comments
 (0)