1
0
Fork 0

sb-internet: read connections rather than devices

This commit is contained in:
Luca Bilke 2024-09-23 11:31:06 +02:00
parent b1aadcd1a4
commit 827311fb6a
1 changed files with 35 additions and 29 deletions

View File

@ -1,15 +1,17 @@
#!/bin/sh
. "colors"
shift=""
status() {
nmcli --terse device status | awk -v device="$1" -F: '$1 == device { print $3 }'
}
wifi() {
wireless() {
if grep -vxq '0x\(1\|9\)003' "$info/flags"; then
icon="󰀞"
else
case "$state" in
case "$(status "$device")" in
connected)
percent=$(awk -v interface="$device:" '$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
case 1 in
$((percent >= 80))) icon="󰤨" ;;
@ -19,52 +21,56 @@ wifi() {
$((percent >= 0))) icon="󰤯" ;;
esac
;;
disconnected) icon="󰤮" ;;
disconnected) return ;;
*) icon="󰤫" ;;
esac
printf "%b" "$shift$icon $connection"
shift=" "
wireless_status="${wireless_status:-}${icon} "
fi
}
wireguard() {
printf "%b" "$shift󰖂 $connection"
shift=" "
}
tun() {
printf "%b" "$shift󰖂 $connection"
shift=" "
}
ethernet() {
case "$state" in
case "$(status "$device")" in
connected) icon="󰱓" ;;
unavailable) icon="󰅛" ;;
disconnected) icon="󰲛" ;;
unavailable | disconnected) return ;;
*) icon="󰛵" ;;
esac
printf "%b" "$shift$icon"
shift=" "
ethernet_status="${ethernet_status:-}${icon} "
}
wireguard() {
wireguard_status="${wireguard_status:-}󰖂 ${name} "
}
vpn() {
vpn_status="${vpn_status:-}󰖂 ${name} "
}
fallback() {
:
}
output() {
printf "%b" "${wireless_status}${ethernet_status}${wireguard_status}${vpn_status}" | sed 's/ $//'
}
IFS="
"
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)"
for x in $(nmcli --terse connection show --active); do
name="$(echo "$x" | cut -d: -f1)"
type="$(echo "$x" | cut -d: -f3)"
device="$(echo "$x" | cut -d: -f4)"
info="/sys/class/net/${device}"
case "$type" in
wifi | wireguard | ethernet | tun) $type ;;
*wireless) wireless ;;
*ethernet) ethernet ;;
wireguard | vpn) $type ;;
*) fallback ;;
esac
unset device type state connection info icon
unset name type device info icon
done
output