aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/script/bar-networking
blob: 32a7a8f10e23ba19a67894bd6baeaf6c6f09d56a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh

data="$(nmcli -t -f GENERAL.TYPE,IP4.ADDRESS device show)"

for conn_type in ethernet wifi; do
	if   [ "$conn_type" = "wifi"     ]; then icon=""
	elif [ "$conn_type" = "ethernet" ]; then icon=""
	fi

	conn_status="$(echo "$data" | grep -A 1 "GENERAL.TYPE:$conn_type$")"
	if echo "$conn_status" | grep -q "IP4.ADDRESS"; then
		export "$conn_type"_status="$(printf "%s" "$icon " && echo "$conn_status" |
			grep "IP4.ADDRESS" | cut -d ":" -f 2 | cut -d "/" -f 1)"
	elif [ -z "$ethernet_status" ] && [ "$conn_type" = "wifi" ]; then
		wifi_status="$icon disconnected"
	fi
done
nmcli device status | grep -q "wireguard.*connected" && wg_status="(WG)"

# shellcheck disable=SC2154
echo "$wifi_status $ethernet_status $wg_status" | sed 's/  */ /g; s/\s*$//; s/^\s*//'