dwmblock-internet (1604B)
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 7 # Interfaces: 8 # (list with `nmcli --get-values GENERAL.DEVICE,GENERAL.TYPE device show`) 9 wired=enxc84bd604a6e7 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 pgrep -f nmtui || "$TERMINAL" -e nmtui 16 pkill -RTMIN+5 dwmblocks ;; 17 2) notify "Connected to $(/sbin/iwgetid -r)" '' ;; 18 3) notify Wireless "Toggling wireless..." 19 rfkill toggle wlan 20 pkill -RTMIN+5 dwmblocks ;; 21 6) "$TERMINAL" -e "$EDITOR" "$0" ;; 22 esac 23 24 case "$(cat /sys/class/net/$wireless/operstate 2>/dev/null)" in 25 down) 26 if rfkill list wlan | grep 'Soft blocked: no' >/dev/null 2>&1; then 27 wifiicon="📡 " 28 else 29 wifiicon="📡🛑 " 30 fi ;; 31 up) wifiicon="$(awk -v pat="^\\\\s*$wireless" '$0 ~ pat { print "📶", int($3) "% " }' /proc/net/wireless)" ;; 32 # might need to do some calculations if this doesn't match up with `iwconfig` link quality 33 # up) wifiicon="$(awk '/^\s*e/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;; 34 esac 35 36 ethicon="$(sed 's/down/❎/;s/up/🌐/' /sys/class/net/$wired/operstate 2>/dev/null)" 37 if nmcli --terse device status | grep '^tun.*:connected' >/dev/null 2>&1; then 38 vpnicon=' 🔒' 39 else 40 vpnicon=' ' 41 fi 42 # vpnicon="$(sed 's/down/ /;s/up/🔒/;s/unknown/ /;' /sys/class/net/tun*/operstate 2>/dev/null)" 43 44 printf "%s%s%s" "$wifiicon" "$ethicon" "$vpnicon"