dwmblock-internet (1836B)
1 #!/bin/sh 2 # dwmblocks script for internet information 3 # Show wifi 📶 and percent strength or 📡 if none. 4 # Show 🌐 if connected to ethernet or ❎ if none. 5 # Show 🔒 if a vpn connection is active 6 # Interfaces: 7 # (list with `nmcli --get-values GENERAL.DEVICE,GENERAL.TYPE device show`) 8 wired="enp0s31f6 eth0" 9 wireless=wlp0s20f3 10 # there's probably a way to change these but I'd have to know all files to update... 11 12 case "$BUTTON" in 13 1) 14 if pgrep -f nmtui >/dev/null 2>&1; then 15 wmctrl -Fa 'nmtui' 16 else 17 "$TERMINAL" -e nmtui 18 fi 19 pkill -RTMIN+5 dwmblocks ;; 20 2) notify "Connected to $(/sbin/iwgetid -r)" '' ;; 21 3) notify Wireless "Toggling wireless..." 22 rfkill toggle wlan 23 pkill -RTMIN+5 dwmblocks ;; 24 6) "$TERMINAL" -e "$EDITOR" "$0" ;; 25 esac 26 27 # Wireless 28 case "$(cat /sys/class/net/$wireless/operstate 2>/dev/null)" in 29 down) 30 if rfkill list wlan | grep 'Soft blocked: no' >/dev/null 2>&1; then 31 wifiicon="📡 " 32 else 33 wifiicon="📡🛑 " 34 fi ;; 35 up) wifiicon="$(awk -v pat="^\\\\s*$wireless" '$0 ~ pat { print "📶", int($3) "% " }' /proc/net/wireless)" ;; 36 # might need to do some calculations if this doesn't match up with `iwconfig` link quality 37 # up) wifiicon="$(awk '/^\s*e/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;; 38 esac 39 40 # Wired 41 ethicon="" 42 for eth in $wired; do 43 ethicon="$ethicon$(cat /sys/class/net/$eth/operstate 2>/dev/null)" 44 done 45 case "$ethicon" in 46 *up*) ethicon='🌐';; 47 *) ethicon='❎';; 48 esac 49 50 # VPN 51 if nmcli --terse device status | grep -e ':[^:]*tun[^:]*:connected' | grep -Ev '^(virbr|vnet|vboxnet)' >/dev/null 2>&1; then 52 vpnicon=' 🔒' 53 else 54 vpnicon=' ' 55 fi 56 # vpnicon="$(sed 's/down/ /;s/up/🔒/;s/unknown/ /;' /sys/class/net/tun*/operstate 2>/dev/null)" 57 58 printf "%s%s%s" "$wifiicon" "$ethicon" "$vpnicon"