1
0
Fork 0

sb-internet: rewrite with nmcli

This commit is contained in:
Luca Bilke 2024-07-24 12:00:45 +02:00
parent 0f7c7607e7
commit 28b7dab483
Signed by: luca
GPG Key ID: F6E11C9BAA7C82F5
1 changed files with 45 additions and 56 deletions

View File

@ -1,73 +1,62 @@
#!/bin/sh #!/bin/sh
# TODO: rewrite this with nmcli
shift="" shift=""
# Ethernet wifi() {
for if in /sys/class/net/*; do if grep -vxq '0x\(1\|9\)003' "$info/flags"; then
[ "$(cat "$if/type")" = 1 ] || continue icon="󰀞"
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="󰀞"
else else
case "$(cat "$if/operstate")" in case "$state" in
up) connected)
percent=$(awk -v interface="$INTERFACE" '$1==interface {gsub(/[^0-9]/,"",$3); print $3}' /proc/net/wireless) percent=$(awk -v interface="$device:" '$1==interface {gsub(/[^0-9]/,"",$3); print $3}' /proc/net/wireless)
# shellcheck disable=SC2194 # shellcheck disable=SC2194
case 1 in case 1 in
$((percent >= 0))) wifi_icon="󰤯" ;; $((percent >= 80))) icon="󰤨" ;;
$((percent >= 20))) wifi_icon="󰤟" ;; $((percent >= 60))) icon="󰤥" ;;
$((percent >= 40))) wifi_icon="󰤢" ;; $((percent >= 40))) icon="󰤢" ;;
$((percent >= 60))) wifi_icon="󰤥" ;; $((percent >= 20))) icon="󰤟" ;;
$((percent >= 80))) wifi_icon="󰤨" ;; $((percent >= 0))) icon="󰤯" ;;
esac esac
;; ;;
down) wifi_icon="󰤮" ;; disconnected) icon="󰤮" ;;
*) wifi_icon="󰤫" ;; *) icon="󰤫" ;;
esac esac
printf "%b" "$shift$icon $connection"
shift=" "
fi fi
}
printf "%b" "$shift$wifi_icon $ifname" wireguard() {
printf "%b" "$shift󰖂 $connection"
shift=" " shift=" "
done }
# Wireguard ethernet() {
for if in /sys/class/net/*; do case "$state" in
eval "$(cat "$if/uevent")" connected) icon="󰱓" ;;
unavailable) icon="󰅛" ;;
disconnected) icon="󰲛" ;;
*) icon="󰛵" ;;
esac
[ "$DEVTYPE" = "wireguard" ] || continue printf "%b" "$shift$icon"
unset DEVTYPE
ifname=$(basename "$if")
printf "%b" "$shift󰖂 $ifname"
shift=" " shift=" "
done }
printf "\n" fallback() {
:
}
for x in $(nmcli --terse device status); do
device="$(echo "$x" | cut -d: -f1)"
type="$(echo "$x" | cut -d: -f2)"
state="$(echo "$x" | cut -d: -f3)"
connection="$(echo "$x" | cut -d: -f4)"
info="/sys/class/net/${device}"
case "$type" in
wifi | wireguard | ethernet) $type ;;
*) fallback ;;
esac
unset device type state connection info icon
done