blob: acbb1f4007b927ed24ca12e53e92d9090d7b28e9 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!/bin/sh
# Show wifi 🛜 and percent strength or 📡 if none.
# Show 🌐 if connected to ethernet or ❎ if none.
# Show 🛰️ if a vpn connection is active
set_eth() {
eth_con="$(nmcli -t -f NAME,TYPE,DEVICE connection show |
awk -F: '$2=="ethernet" && $3!="" { print $1; exit }')"
wifi_con="$(nmcli -t -f NAME,TYPE connection show |
awk -F: '$2=="wifi" { print $1; exit }')"
if [ -n "$eth_con" ]; then
nmcli connection modify "$eth_con" ipv4.method auto
nmcli connection modify "$eth_con" ipv4.never-default no
nmcli connection modify "$eth_con" ipv4.dns-priority -42
nmcli connection modify "$eth_con" ipv4.route-metric 100
nmcli connection modify "$eth_con" connection.autoconnect yes
fi
if [ -n "$wifi_con" ]; then
nmcli connection modify "$wifi_con" ipv4.dns-priority 100
nmcli connection modify "$wifi_con" ipv4.route-metric 600
fi
}
case $BLOCK_BUTTON in
1)
"$TERMINAL" -e nmtui
pkill -RTMIN+7 dwmblocks
;;
2)
wifi_dev="$(nmcli -t -f DEVICE,TYPE device |
awk -F: '$2=="wifi" { print $1; exit }')"
wifi_state="$(nmcli -t -f DEVICE,STATE device |
awk -F: -v dev="$wifi_dev" '$1==dev { print $2 }')"
if [ "$wifi_state" = "connected" ]; then
nmcli radio wifi off
notify-send "Wi-Fi" "Wi-Fi disconnected"
else
nmcli radio wifi on
notify-send "Wi-Fi" "Wi-Fi connected"
fi
pkill -RTMIN+7 dwmblocks
;;
3) notify-send "🌐 Internet module" "\- Left click to connect
❌: wifi disabled
📡: no wifi connection
🛜: wifi connection with quality
❎: no ethernet
🌐: ethernet working
🛰: vpn is active
" ;;
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
# Wifi
if grep -q 'up' /sys/class/net/w*/operstate 2>/dev/null; then
if grep -q '^\s*w' /proc/net/wireless; then
wifiicon="$(awk '/^\s*w/ { print "🛜" int($3 * 100 / 70) "%" }' /proc/net/wireless)"
else
wifiicon="📡"
fi
elif grep -q 'down' /sys/class/net/w*/operstate 2>/dev/null; then
wifiicon="❌"
fi
# Ethernet
grep -q 'up' /sys/class/net/e*/operstate && ethericon="🌐" || ethericon="❎"
# TUN
grep -q 'up' /sys/class/net/tun*/operstate 2>/dev/null && tunicon="🛰"
icons=""
[ -n "$wifiicon" ] && icons="${icons}$wifiicon "
[ -n "$ethericon" ] && icons="${icons}$ethericon "
[ -n "$tunicon" ] && icons="${icons}$tunicon "
printf "%s\n" "${icons% }"
|