diff --git a/.local/libexec/statusbar/sb-internet b/.local/libexec/statusbar/sb-internet index a119ae7d0..1c1e42b66 100755 --- a/.local/libexec/statusbar/sb-internet +++ b/.local/libexec/statusbar/sb-internet @@ -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