config/.local/bin/xmobar-status-net

73 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
dev_wifi=$(cat "$HOME"/.config/xmobar/dev_wifi)
dev_eth=$(cat "$HOME"/.config/xmobar/dev_eth)
dev_vpn=$(cat "$HOME"/.config/xmobar/dev_vpn)
yellow=#b58900
red=#dc322f
magenta=#d33682
green=#859900
# connectivity status
# states are:
# none (no connectivity)
# portal (behind captive portal)
# limited (connected to network but no internet access)
# full (full internet connectivity)
# unknown
std_color=$magenta
wifi_icon=""
connectivity="$(nmcli networking connectivity)"
case $connectivity in
none) color=$red; icon="" ;; # f056 fa-minus-circle
portal) color=$yellow; icon="" ;; # f05c fa-times-circle-o
limited) color=$yellow; icon="" ;; # f01b fa-arrow-circle-o-up
full) color=$std_color; icon="" ;; # f0aa fa-arrow-circle-up
*) color=$red; icon="" ;; # f29c fa-question-circle-o
esac
eth="$(ip -o address | grep -i "$dev_eth *inet ")"
if [ -n "$eth" ]
then
#eth="${eth##*inet }"
speed="$(cat /sys/class/net/"$dev_eth"/speed)"
case $speed in
10) speed="10Base-T" ;;
100) speed="100Base-T" ;;
1000) speed="Gigabit" ;;
*) speed="UNKNOWN $speed" ;;
esac
#eth_status=" <fn=1></fn> $speed ${eth%%/*}"
eth_status=" <fn=1> </fn> $speed"
fi
ssid="$(iw dev "$dev_wifi" link | grep -i SSID)"
if [ -n "$ssid" ]
then
signal="$(iw dev "$dev_wifi" station dump | grep -E '[^ ]signal avg')"
signal="${signal#*-}"
signal="${signal%% *}"
signal="$((2*(100-signal)))"
signal=$((signal/5*5)) # get rid of some jitter
((signal > 100)) && signal=100
wifi_status=" <fn=1>$wifi_icon </fn> <fc=$green>${signal}</fc>% ${ssid##*SSID: }"
fi
vpn="$(ip -o address | grep -i "$dev_vpn *inet ")"
if [ -n "$vpn" ]
then
#vpn="${vpn##*inet }"
#vpn_status="<fn=1></fn> ${vpn%%/*}"
vpn_status="<fn=1> </fn> "
color=$green
else
vpn_status="<fn=1> </fn> "
fi
echo "<fc=$color>${vpn_status}<fn=1>$icon </fn>${connectivity##*full}$wifi_status$eth_status</fc>"