75 lines
1.8 KiB
Bash
Executable File
75 lines
1.8 KiB
Bash
Executable File
#!/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
|
|
|
|
# Global config
|
|
source config
|
|
|
|
case $BLOCK_BUTTON in
|
|
1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;;
|
|
3) notify-send "🌐 Internet module" "\- Click to connect
|
|
❌: wifi disabled
|
|
📡: no wifi connection
|
|
📶: wifi connection with quality
|
|
❎: no ethernet
|
|
🌐: ethernet working
|
|
🔒: vpn is active
|
|
" ;;
|
|
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
|
|
esac
|
|
|
|
# Emoji used by module
|
|
i_low=" "
|
|
i_med=" "
|
|
i_high=" "
|
|
i_max=" "
|
|
i_none=" "
|
|
i_nowifi=" $we"
|
|
i_searching=" $we"
|
|
i_vpn=" "
|
|
i_eth=" "
|
|
i_ethoff=" "
|
|
|
|
ssid_max=10
|
|
|
|
# status2d patch alternating background
|
|
# background="^b#333333^"
|
|
# background="^b#222222^"
|
|
|
|
|
|
wifi_state=$(cat /sys/class/net/w*/operstate 2>/dev/null)
|
|
ethernet=$(sed "s/down/$i_ethoff/;s/up/$i_eth/" /sys/class/net/e*/operstate 2>/dev/null)
|
|
vpnconnection=$(sed "s/.*/$i_vpn/" /sys/class/net/tun*/operstate 2>/dev/null)
|
|
|
|
# Check if network is connected.
|
|
if [ "$wifi_state" == "up" ] ; then
|
|
net=$(awk '/^\s*w/ { print int($3 * 100 / 70) }' /proc/net/wireless)
|
|
net=${net:-0}
|
|
ssid=$(iwgetid -r)
|
|
|
|
case 1 in
|
|
$((net > 90)) ) wifiicon="$i_max" ;;
|
|
$((net > 70)) ) wifiicon="$i_high" ;;
|
|
$((net > 30)) ) wifiicon="$i_med" ;;
|
|
$((net > 10)) ) wifiicon="$i_low" ;;
|
|
* ) wifiicon="$i_none" ;;
|
|
esac
|
|
elif [ "$wifi_state" == "down" ] ; then
|
|
flags=$(cat /sys/class/net/w*/flags)
|
|
if [[ "$flags" == "0x1003" ]]; then
|
|
wifiicon="$i_searching"
|
|
else
|
|
wifiicon="$i_nowifi"
|
|
fi
|
|
else
|
|
wifiicon="$i_nowifi"
|
|
fi
|
|
|
|
if [[ ${#ssid} > $ssid_max ]]; then
|
|
ssid="${ssid::ssid_max}..."
|
|
fi
|
|
|
|
printf " $background$wb%s%s%s %.15s^d^" "$wifiicon" "$ethernet" "$vpnconnection" "$ssid"
|