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