1
0
Fork 0
dotfiles/.local/libexec/statusbar/sb-nettraf

21 lines
519 B
Plaintext
Raw Normal View History

2022-07-04 21:36:33 +02:00
#!/bin/sh
2024-02-03 18:57:22 +01:00
# . "$HOME/.local/libexec/statusbar/colors"
# TODO: Coloring based on speed
2023-02-21 17:49:55 +01:00
2022-07-04 21:36:33 +02:00
update() {
2023-02-07 17:19:53 +01:00
sum=0
for arg; do
read -r i <"$arg"
sum=$((sum + i))
done
2024-02-08 17:04:57 +01:00
cache=$XDG_RUNTIME_DIR/${1##*/}
2023-02-07 17:19:53 +01:00
[ -f "$cache" ] && read -r old <"$cache" || old=0
printf "%b" "$sum\n" >"$cache"
printf "%b" "$((sum - old))\n"
2022-07-04 21:36:33 +02:00
}
2022-07-04 21:36:33 +02:00
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
2024-02-03 18:57:22 +01:00
2024-02-03 18:21:24 +01:00
printf "%b%5sB %b%5sB%b" "" "$(numfmt --to=iec "$rx")" "" "$(numfmt --to=iec "$tx")" "\n"