77 lines
1.5 KiB
Bash
Executable File
77 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
. libsb
|
|
|
|
status() {
|
|
nmcli --terse device status | awk -v device="$1" -F: '$1 == device { print $3 }'
|
|
}
|
|
|
|
wireless() {
|
|
if grep -vxq '0x\(1\|9\)003' "$info/flags"; then
|
|
icon=""
|
|
else
|
|
case "$(status "$device")" in
|
|
connected)
|
|
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="" ;;
|
|
$((percent >= 60))) icon="" ;;
|
|
$((percent >= 40))) icon="" ;;
|
|
$((percent >= 20))) icon="" ;;
|
|
$((percent >= 0))) icon="" ;;
|
|
esac
|
|
;;
|
|
disconnected) return ;;
|
|
*) icon="" ;;
|
|
esac
|
|
|
|
wireless_status="${wireless_status:-}${icon} ${name} "
|
|
fi
|
|
}
|
|
|
|
ethernet() {
|
|
case "$(status "$device")" in
|
|
connected) icon="" ;;
|
|
unavailable | disconnected) return ;;
|
|
*) icon="" ;;
|
|
esac
|
|
|
|
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 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
|
|
*wireless) wireless ;;
|
|
*ethernet) ethernet ;;
|
|
wireguard | vpn) $type ;;
|
|
*) fallback ;;
|
|
esac
|
|
|
|
unset name type device info icon
|
|
done
|
|
|
|
output
|