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