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

21 lines
519 B
Bash
Executable File

#!/bin/sh
# . "$HOME/.local/libexec/statusbar/colors"
# TODO: Coloring based on speed
update() {
sum=0
for arg; do
read -r i <"$arg"
sum=$((sum + i))
done
cache=$XDG_RUNTIME_DIR/${1##*/}
[ -f "$cache" ] && read -r old <"$cache" || old=0
printf "%b" "$sum\n" >"$cache"
printf "%b" "$((sum - old))\n"
}
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
printf "%b%5sB %b%5sB%b" "" "$(numfmt --to=iec "$rx")" "" "$(numfmt --to=iec "$tx")" "\n"