aboutsummaryrefslogtreecommitdiff
path: root/i3blocks/i3internet.sh
blob: 3e632767f549cccf02cfc02b68126c7e257570a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh

# Shows status of wifi and ethernet connections.

# Depends on nmcli and ip for IPs
case $BLOCK_BUTTON in
	1) i3-msg "exec urxvt -title \"floating\" -e nmtui" >/dev/null ;;
esac

wifiDev="$CONFIG_WIFI_DEV"
ethDev="$CONFIG_ETH_DEV"
tick="✅"
wifiSymbol=""
wifi=""
ethSymbol=""
eth=""

if [ -n "$wifiDev" ]; then
	wifiSymbol="📶"
	wstatus="$(cat "/sys/class/net/$wifiDev/operstate")"
	if [ "$wstatus" = "down" ]; then
		wifi="❌"
	elif nmcli | grep -F -q "$wifiDev: connecting "; then
		step="$(nmcli | grep -F "$wifiDev: connecting " | sed 's/^.*(/(/;s/).*$/)/')"
		wifi="$tick <span color='#fabd2f'>$(nmcli | grep -F "$wifiDev: " |
			cut -d' ' -f5-) $step</span>"
	else
		# with IP
		#wifi="$tick$(nmcli | fgrep "$wifiDev: connected to " |
		#cut -d' ' -f4-) ($(ip addr show $wifiDev | fgrep "inet " |
		#cut -d' ' -f6)) ($(egrep "^\s*w" /proc/net/wireless |
		#awk '{print int($3 * 100 / 70)"%"}'))"
		# with name
		wifi="$tick <span color='#79ff79'>$(nmcli |
			grep -F "$wifiDev: connected to " |
			cut -d' ' -f4-) ($(grep -E '^\s*w' /proc/net/wireless |
			awk '{print int($3 * 100 / 70)"%"}'))</span>"
	fi
fi

if [ -n "$ethDev" ]; then
	ethSymbol="🌐"
	estatus="$(cat "/sys/class/net/$ethDev/operstate")"
	if ! nmcli | grep -F -q "$ethDev"; then
		eth="❌❗ No $ethDev"
	elif [ "$estatus" = "down" ]; then
		eth="❌"
	else
		# with IP
		#eth=$(ip addr show $ethDev | fgrep "inet " | cut -d' ' -f6)
		# no IP
		eth=$tick
	fi
fi

echo "$wifiSymbol$wifi  $ethSymbol$eth" | sed 's/^ *//' | sed 's/ *$//'
exit 0