1
0
Fork 0

sb-internet: refactor

This commit is contained in:
Luca Bilke 2024-07-23 20:45:42 +02:00
parent 0da16c2e24
commit 0f7c7607e7
No known key found for this signature in database
GPG Key ID: C9E851809C1A5BDE
1 changed files with 44 additions and 10 deletions

View File

@ -1,38 +1,72 @@
#!/bin/sh
# TODO: rewrite this with nmcli
shift=""
# Ethernet
for if in /sys/class/net/*; do
eval "$(cat "$if/uevent")"
[ -z "$DEVTYPE" ] || continue
printf "%b" "$shift󰈁"
[ "$(cat "$if/type")" = 1 ] || continue
ifname=$(basename "$if")
echo "$ifname" | grep -q \
-e "^br" \
-e "^docker" &&
continue
case "$(cat "$if/operstate")" in
up) eth_icon="󰱓" ;;
down) eth_icon="󰅛" ;;
*) eth_icon="󰛵" ;;
esac
printf "%b" "$shift$eth_icon $ifname"
shift=" "
done
# WLAN
for if in /sys/class/net/*; do
eval "$(cat "$if/uevent")"
[ "$DEVTYPE" = "wlan" ] || continue
unset DEVTYPE
ifname=$(basename "$if")
if grep -vxq '0x\(1\|9\)003' "$if/flags"; then
wifi_icon=""
wifi_icon="󰀞"
else
case "$(cat "$if/operstate")" in
up) wifi_icon="󰖩" ;;
down) wifi_icon="󰖪" ;;
dormant) wifi_icon="󰤯" ;;
up)
percent=$(awk -v interface="$INTERFACE" '$1==interface {gsub(/[^0-9]/,"",$3); print $3}' /proc/net/wireless)
# shellcheck disable=SC2194
case 1 in
$((percent >= 0))) wifi_icon="󰤯" ;;
$((percent >= 20))) wifi_icon="󰤟" ;;
$((percent >= 40))) wifi_icon="󰤢" ;;
$((percent >= 60))) wifi_icon="󰤥" ;;
$((percent >= 80))) wifi_icon="󰤨" ;;
esac
;;
down) wifi_icon="󰤮" ;;
*) wifi_icon="󰤫" ;;
esac
fi
percent="$(grep "$INTERFACE" /proc/net/wireless | tr -s ' ' | cut -d ' ' -f3 | tr -dc "[:digit:]")"
printf "%b" "$shift$wifi_icon $percent"
printf "%b" "$shift$wifi_icon $ifname"
shift=" "
done
# Wireguard
for if in /sys/class/net/*; do
eval "$(cat "$if/uevent")"
[ "$DEVTYPE" = "wireguard" ] || continue
printf "%b" "$shift󰖂"
unset DEVTYPE
ifname=$(basename "$if")
printf "%b" "$shift󰖂 $ifname"
shift=" "
done